Is it possible for javascript to access a database directly? I feel my question is rhetorical owing to the fact that this is a security issue. But is it possible anyway?
-
2Let's think about this question. Javascript is exposed to the client. If we connected to the database the connection info would be stored on ding ding ding the C L I E N T. Holy s*** batman...The Muffin Man– The Muffin Man2011-04-02 08:03:48 +00:00Commented Apr 2, 2011 at 8:03
6 Answers
It is possible!
with the new html5 feature, js can connect through WebSql.
a live example : http://html5demos.com/database
the syntax is similar to all the other sql wrappers :
var db = openDatabase('mydb', '1.0', 'my first database', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE foo (id unique, text)');
});
it is currently supported by chrome, safari and opera
here's a tutorial : http://html5doctor.com/introducing-web-sql-databases/
Comments
Depends on what DB you want to use.
CouchDB is HTTP addressable, so can be hit from JS. http://couchdb.apache.org/
Comments
Not from the browser. Javascript can be used on the server to set up server side functionality, though.
6 Comments
http://www.daniweb.com/web-development/php/threads/197091/update-mysql-table-using-javascript You need to look into the jQuery.ajax function, this will send/receive information from a PHP document.
What you need to do is set up a PHP document that will handle the the form as though it were being posted to by http, or by setting the action on the tag.
You then need to make a function similar to this: