Ashwin Krishnamurthy
Ashwin Krishnamurthy

Reputation: 3758

Javascript and Database Connectivity

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?

Upvotes: 5

Views: 11701

Answers (6)

user2775850
user2775850

Reputation: 11

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:

Upvotes: 0

Mahesh
Mahesh

Reputation: 1

Yes it is.

I don't know more about it but javascript can connect with DB using ADODB.Connection.

Upvotes: 0

Daniel Willis
Daniel Willis

Reputation: 54

Depends on what DB you want to use.

CouchDB is HTTP addressable, so can be hit from JS. http://couchdb.apache.org/

Upvotes: 2

gion_13
gion_13

Reputation: 41533

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/

Upvotes: 6

picardo
picardo

Reputation: 24886

Not from the browser. Javascript can be used on the server to set up server side functionality, though.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Is it possible for javascript to access a database directly?

No. Setup a server side script which will talk the database and then call this script with AJAX.

Upvotes: 3

Related Questions