html里怎么用javascript连接数据库?
发布网友
发布时间:2022-04-22 04:31
我来回答
共1个回答
热心网友
时间:2024-01-22 10:54
理论上不建议这样连,但是也可以连的
代码如下:
<script type="text/javascript" language="javascript" charset="gb2312">
<!--
function getCountFromDB() {
var filePath = location.href.substring(0, location.href.indexOf("index.html"));
var path = filePath + "MyData.mdb";
path = path.substring(8);
var updateCnt = 0;
var sqlSelCnt = "SELECT * FROM [user]";
var con = new ActiveXObject("ADODB.Connection");
con.Provider = "Microsoft.Jet.OLEDB.4.0";
con.ConnectionString = "Data Source=" + path;
con.open;
var rs = new ActiveXObject("ADODB.Recordset");
rs.open (sqlSelCnt,con);
while (!rs.eof) {
var cnt = rs.Fields("content");
document.write (cnt);
rs.moveNext;
}
rs.close();
rs = null;
}