html里怎么用javascript连接数据库?
展开全部
理论上不建议这样连,但是也可以连的
代码如下:
<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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询