admin管理员组

文章数量:1402826

I want to create a database to hold images, then have the images pulled out of the database into an array.

Every ten minutes or so I want the new images to replace the old images in the array.

I will be using JavaScript to update the webpage every 10 minutes based on the user's clock.

Should I store the images in MySQL, or in a different database that is more JavaScript friendly?

I want to create a database to hold images, then have the images pulled out of the database into an array.

Every ten minutes or so I want the new images to replace the old images in the array.

I will be using JavaScript to update the webpage every 10 minutes based on the user's clock.

Should I store the images in MySQL, or in a different database that is more JavaScript friendly?

Share Improve this question edited Jun 13, 2011 at 22:42 p.campbell 101k70 gold badges262 silver badges326 bronze badges asked Jun 13, 2011 at 22:32 toratora 312 silver badges3 bronze badges 3
  • 1 You actually expect a user to stay on a single page for 10+ minutes? The database layer will have to be interfaced via a server side script anyway so there isn't really such a thing as a "javascript friendly" database. – Endophage Commented Jun 13, 2011 at 22:36
  • 1 Why bother with a database? What will a database give you that you don't get by putting the image files in a /resources/images (or whatever) folder in your web project and having your JavaScript pull the images from there directly? Given your requirement to update based on the user's clock just name the image files in a way that you can map to a name based on the current time. – nnnnnn Commented Jun 14, 2011 at 0:22
  • Endophage, CouchDB is very much a "javascript friendly" database. Not only does it use HTTP as it's access mechanism (for easy AJAX DB operations), but the views within it are actually written in JS. Check it out! – machineghost Commented Jun 14, 2011 at 16:04
Add a ment  | 

5 Answers 5

Reset to default 1

JavaScript in the browser has no way of interacting with SQL databases directly. If you want to use one, you'll need to write an interface for it on the server (in Python, PHP or something).

If you could avoid using a database (as just use files on a server), it would be simpler. Just the image files, with JSON files for metadata, might be appropriate for some uses.

Images should be stored on the file system and paths to the images should be stored in the database. This SO question has a good detailed answer as to why. MySQL works just fine for storing the paths. However, Javascript itself has no way to municate directly with the database - you'll need to have an intermediate served file (php, python, etc) that will expose the functionality that you're looking for. You can tap into this using Javascript (AJAX).

About the only way to interact with a database from javascript is to use a server-side intermediary such as perl, php, python, asp, java, etc...

Generally, you would write a web service on the server side that performs the desired database interaction. You then invoke this web service from javascript code.

If you need data back from the server then Json or Xml is the usual method of information exchange.

CouchDB is VERY Javascript friendly; in fact, if you use CouchApp, you can use pure CouchDB to run your entire site; no need for a Python/Ruby/Node.js/whatever layer! I definitely remend it if you're looking for a "pure JS" database.

Oh, and I should mention that Couch uses HTTP as it's access mechanism, so you can totally put records in/get records out of it using basic AJAX :-D

This is new, but that's basically the entire purpose of SimpleDB (https://sdbapi.jdbdu.xyz/). It consists of only three mands, so you need like zero database experience in order to use it. Hope this helps.

本文标签: Creating a database to use with JavaScriptStack Overflow