Home > Backend Development > PHP Tutorial > PHP连接操作access数据库实例_php技巧

PHP连接操作access数据库实例_php技巧

WBOY
Release: 2016-05-16 20:18:48
Original
969 people have browsed it

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

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

/*
创建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 "
";
 $rs->Movenext(); //将记录集指针下移
}
$rs->close();
?>

这样运行就没问题了····
以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template