Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there JavaScript bindings for MySQL?

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 will not work

Some background: I want to create something like a GUI front end for a MySQL database (that's not what it is, but it's close enough). I'm thinking about doing this as a local HTML page using JavaScript but for that to work I would need MySQL bindings for JavaScript under Firefox. I already have a working prototype in under 100 LOC, but it requires a web server, and for reasons that are beyond this question, that won't work.

NOTE: both the database and the JavaScript code will be running locally and are not intended as a public page. In fact the HTML file will loaded as a file://// file. The only reason I'm using JavaScript is that it's the only available system for doing GUI stuff where I need it.

I'm willing to install plugins, DLL's, Windows dependent stuff or what not to make this work.


Edit: It looks like the answer is, "It can be done, but it's going to be painful". As one of my options is to just spew out all the data as files (ugly, and not too flexible, but it would work) I think I'm not going to pursue this.

like image 347
BCS Avatar asked Nov 18 '08 07:11

BCS


People also ask

Can you use JavaScript in MySQL?

JavaScript is a client-side language that runs in the browser and MySQL is a server-side technology that runs on the server. You need to use the server-side language Node. js to connect to the MySQL Database.

What is binding in MySQL?

Binding sends the data to be inserted into MySQL separately from the query, and understands how to parse it for insertion without risking safety of the database. With the execute function, you just pass the array with keys corresponding to the placeholder data you defined in the prepare function.


1 Answers

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

like image 51
Guillaume Avatar answered Sep 21 '22 00:09

Guillaume