2

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?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
tora
  • 31
  • 2
  • 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 Jun 13 '11 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 Jun 14 '11 at 00: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 Jun 14 '11 at 16:04

5 Answers5

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.

Jeremy
  • 1
  • 85
  • 340
  • 366
1

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 communicate 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).

Community
  • 1
  • 1
Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
1

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 recommend 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

machineghost
  • 33,529
  • 30
  • 159
  • 234
1

About the only way to interact with a database from javascript is to use a server-side intermediary such as perl, php, python, asp.net, 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.

Matthew Cox
  • 13,566
  • 9
  • 54
  • 72
1

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