views:

112

answers:

3

Is it possible to connect database with javascript.

A: 

Not directly, but you can use WebServices to build your javascript-accesible business logic.
Here you can find an article how to handle webservices in javascript.

This solution is much safer then direct connection to database (for example your connection string is not exposed) and it can be use on static pages without any problems.

ŁukaszW.pl
A: 

Please see if this is helpful to you :)

Personally I believe if you can include server-side javascript, then there must be a way.

Michael Mao
+2  A: 

Yes, absolutely. Behold the DBSlayer: http://code.nytimes.com/projects/dbslayer/wiki

Developed by the New York Times to manage their high load, it is a HTTP/JSON to MySQL proxy. Just make an SQL request to it via HTTP and it will return a JSON object.

However, this is not really a good idea for both security reasons (people can simply delete whole tables and databases or get access to data you don't want them to see) and code readability reasons (your code will depend too much on database structure). But, if you're doing this on the server side via Node.js or Rhino for example then it's OK.

slebetman
It's possible but I wouldn't suggest beginners to try this method.
Wadih M.