一、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>
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com