1

Using MySQL & Java Script

I want to make a mysql connection in Java Script, then how can i get a table value by using this connection.

ASP.Net code

con.ConnectionString = "Dsn=server1;" + "Uid=root;" + "Pwd=root;"; con.Open();

cmd = new OdbcCommand("Select * from tb_values", con);
cmd.ExecuteNonQuery();

Above Code is working in asp.net, but i want to make a connection & select a values by using JavaScript.

Need JavaScript Code Help.

Gopal
  • 11,712
  • 52
  • 154
  • 229
  • asp.net code executes on the server side, javascript executes on the client side. It is impossible to query the database on the server side from Javascript, unless you have something on the server side to accept queries and return JSON. – Paul Tomblin Jul 04 '10 at 15:16

4 Answers4

3

Above Code is working in asp.net, but i want to make a connection & select a values by using JavaScript.

That's not possible with javascript otherwise world would have seen your database connection code.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
1

Client side case:

The JS client side shouldn't be able to do that.

Server side case:

If you absolutely want to have JS on server side you might consider node.js, and a little google on "node js mysql".

bakkal
  • 54,350
  • 12
  • 131
  • 107
0

With HTML5 you can create and query tables in the client side. Take a look at this post about HTML5 Web SQL database, you might find it useful depending on your case.

Guido
  • 46,642
  • 28
  • 120
  • 174
0

@sAc's answer is correct if you want to deploy this code for the public. However, if the database is local to that machine or is registered through an ODBC connection, you probably can access the DB using JavaScript (techinally, I guess this would be JScript). The pages would have to be run as HTAs, HTML Applications, a Microsoft-only sandbox system that removes virtually all restrictions you'd normally get with a web page on the Internet. You do have to change some of the ways you write your code and everything has to be run through ActiveX objects. If that's what you're after, check out Microsoft's documentation on the subject. HTAs are wicked fun to write, by the way.

Andrew
  • 14,204
  • 15
  • 60
  • 104