You shouldn′t use client javascript to access databases for several reasons (bad practice, security issues, etc) but if you really want to do this, here is an example:
(由于多种原因(不良做法,安全问题等),您不应该使用客户端javascript来访问数据库,但如果您真的想这样做,请举例说明:)
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
connection.close;
A better way to connect to a sql server would be to use some server side language like PHP, Java, .NET, among others.
(连接到SQL服务器的更好方法是使用一些服务器端语言,如PHP,Java,.NET等。)
Client javascript should be used only for the interfaces. (客户端javascript应仅用于接口。)
And there are rumors of an ancient legend about the existence of server javascript, but this is another story.
(有传言说有关服务器javascript存在的古老传说,但这是另一个故事。)
;) (;))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…