Home >Backend Development >PHP Tutorial >PHP连接access数据库_php实例

PHP连接access数据库_php实例

WBOY
WBOYOriginal
2016-06-07 17:13:35838browse

因为之前做的PingSwitch要做一个WEB展示的前端,因为一开始用了Delphi和access的结构,而Delphi与MySQL的连接又相对麻烦,最后只能选择用PHP+Access的组合,比较奇怪,但是也合理·····

在PHP中连接access数据库的话我们必须ADO来连接,这跟ASP中连接数据库非常的类似。下边给出了一段DEMO供大家参考。

<&#63;PHP
/*
创建ADO连接
*/
$conn = @new COM("ADODB.Connection") or die ("ADO Connection faild.");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("DATUM/cnbt.mdb");
$conn->Open($connstr);
/*
创建记录集查询
*/
$rs = @new COM("ADODB.RecordSet");
$rs->Open("select * from dbo_dirs",$conn,1,3);
/*
循环读取数据
*/
while(!$rs->eof){
 echo "$rs->Fields["title"]->Value;
 echo "<br/>";
 $rs->Movenext(); //将记录集指针下移
}
$rs->close();
&#63;>

这样运行就没问题了····

以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn