I want to access a MySQL database directly from JavaScript code in an HTML page in Firefox.
Does such a library exist?
To be very clear, CGI+Ajax wil
What you need is a HTTP service that exposes the data you want to fetch with JavaScript.
A small AJAX oriented server side script (PHP, Perl, Ruby, whatever) that takes a few parameters and does the MySQL query, sending the data to the client in an HTTP-and-JavaScript friendly manner (for example as image/jpeg or JSON).
You won't be able to set up anything useful (a working, cross-browser solution) that makes MySQL available to JavaScript. JavaScript can do HTTP, and that's about it. Adapt on the server side.
If you use node.js, I think you might want to take a look at this. http://nodejsdb.org/
JavaScript code lives inside the browser. It can make HTTP requests to the outside, but not really much more. So by design you won't be able to bind to a program running locally. If MySQL did expose an HTTP service, it might be possible, but that's not the case.
You might be able to find a plugin for Firefox that exposes a MySQL API to JavaScript, but I don't know any such plugin.
If you don't specifically need MySQL, but just a database accessible from JavaScript code, have a look at Google Gears. It is a Firefox / Internet Explorer plugin that exposes an SQLite database and a few other goodies.
If you give more information on what you are trying to build, we might be able to give you better advice...
I know this is an old thread, but I think it's still a relevant.
I've used backbone.js as a client lib in the browser. This simplifies (almost trivialises) data access from within the browser.
It depends on RESTful services on the server, and these can easily be provided. By way of example you could use node.js, phpwebsockets or socket.io
HTH
Interesting question. But you sure lift a lot of barriers, selecting a language/environment with lot of voluntary limitations to limit access to the underlying system...
I like Robert's suggestion, Xavante is really lightweight.
Otherwise, I think a viable solution could be to use a Java applet with JDBC access. I think you would need to sign the applet, which shouldn't be a problem.
I searched java applet jdbc in Google and saw lot of promising titles, IBM gives the source code of such applet (for DB2 access but it should be easily adaptable).
[EDIT] There is another way, to wrap mysqllib.dll with an XPCOM DLL, as explained in Native code in javascript. No idea how to really do it, but perhaps it can get you started.
Unfortunately you need a server. Or if you know how to and are ready to be platform/browser locked, you could write a plug-in for your browser of choice (as far as I know there is no DLL for Internet Explorer so you'll need to write one yourself).
You might want to look into a small server that requires no setup. I modified Lua's Xavante server, for a very similar reason to yours, so it runs with no external dependencies, thus I can install/uninstall the application with a single copy/paste.