简体   繁体   中英

How to make a database connection

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.

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 .

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM