php连mssql,access的方法 js连接access数据库
一、php连mssql
$dbhost = '''''''';
$dbuser = ''''''''; //你的mssql用户名
$dbpass = ''''''''; //你的mssql密码
$dbname = ''''''''; //你的mssql库名
$connect=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser","$dbpass");
$sql="select * from content";
$exec=odbc_exec($connect,$sql);
while($row = (odbc_fetch_array($exec)))
{
$row[''''id''''] //获取字段值
...
}
二、php连access
$db=$_SERVER[''''DOCUMENT_ROOT'''']."/PHP_ACCESS/include/#mydb.mdb"; //这裏最好用$_SERVER[''''DOCUMENT_ROOT'''']获取路径
$conn = new COM(''''ADODB.Connection'''') or die(''''can not start Active X Data Objects'''');
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db");
$rs = $conn->Execute(''''SELECT * FROM contents order by id desc'''');
while(!$rs->EOF)
{
echo $rs->Fields[''''name'''']->Value;
$rs->MoveNext();
}
/*释放资源*/
$rs->Close();
$conn->Close();
$rs = null;
$conn = null;
Fatal error: Uncaught exception ''''com_exception'''' with message ''''<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> [Microsoft][ODBC Microsoft Access Driver] Disk or network error.''''
(* xp上出现上述错误,但在2003上能正常运行,可能与电脑ODBC配置有关)???????
三、js连接access数据库
scEngine.js文件
//仿数据库连接池类
function scDBPool(){
try{
this.con=new ActiveXObject("ADODB.Connection");
this.con.Provider="Microsoft.Jet.OLEDB.4.0";
this.rs=new ActiveXObject("ADODB.Recordset");
}catch(e){
this.con=null;
this.rs=null;
}
this.filePath=null;
this.dbPath=null;
};
//设置数据库文件相对(定位文件)路径和数据库名
scDBPool.prototype.setDB=function(dbPath){
this.dbPath=dbPath;
};
//设置数据库定位文件,这一步可以进连接类中,这里写是方便使用任何名字的数据库
scDBPool.prototype.setDBPathPosition=function(urlFile){
var filePath=location.href.substring(0, location.href.indexOf(urlFile));
this.dbPath=(this.dbPath==null||this.dbPath=="") ? "/calendar.mdb" : this.dbPath;
var path=filePath this.dbPath;
//去除path前面的"files://"字符串
this.filePath=path.substring(8);
};
//同数据库建立连接
scDBPool.prototype.connect=function(){
this.filePath="C:\\Documents and Settings\\zhen.wang\\Desktop\\js_calendar\\calendar.mdb"; //access路径
this.con.ConnectionString="Data Source=" this.filePath;
//alert(this.con.ConnectionString);
this.con.open;
};
//执行数据库语句返回结果集
scDBPool.prototype.executeQuery=function(sql){
this.rs.open(sql,this.con);
};
//执行数据库语句不返回结果集
scDBPool.prototype.execute=function(sql){
this.con.execute(sql);
};
//关闭结果集
scDBPool.prototype.rsClose=function(){
this.rs.close();
this.rs=null;
};
//关闭数据连接
scDBPool.prototype.conClose=function(){
this.con.close();
this.con=null;
};
调用:
<html>
<head><title>ddd</title>
<script language="javascript" src="scEngine.js"></script>
</head>
<body>
<script language="javascript">
var db=new scDBPool();
db.setDB("calendar.mdb");
db.connect();
var sql="insert into cTime(Week) values(''''ddd'''') ";
db.execute(sql);
/*
db.executeQuery(sql);
while(!db.rs.eof){
var cnt = db.rs.Fields("Data");
document.write(cnt);
db.rs.moveNext;
}
*/
db.rsClose();
db.conClose();
</script>
</body>
评论

React 18的并发渲染确实是个重大改进,我们在项目中已经升级使用,性能提升明显!