javascript访问MYSQL

Javascript访问MYSQL
1、下载MYSQL的ODBC连接http://www.mysql.com/downloads/connector/odbc/;
2、在JS中建立ODBC连接如下:
var con = new ActiveXObject("ADODB.Connection");
con.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};OPTION=3;SERVER=127.0.0.1;User ID=root;Password=123456;Database=mysql;Port=3306";   
con.open;
var rs = new ActiveXObject("ADODB.Recordset");
rs.open("select * from user", con);
while (!rs.eof) {
var u = rs.Fields("User");
document.write(u);
rs.moveNext;
}
rs.close();
rs = null;  
con.close();
con = null;
需要注意连接字符串中Driver的名称与安装后的ODBC中的Drivers页中的MYSQL名称一致即可!
 
 
 
 
 

你可能感兴趣的:(JavaScript)