Home  >  Article  >  php教程  >  PHP如何连接Access数据库

PHP如何连接Access数据库

WBOY
WBOYOriginal
2016-06-13 10:07:081073browse

D:Accessdb1.mdb
用户名:Admin
密 码:123
请问如何在PHP与此文件建立连接

---------------------------------------------------------------

第一种方式是用ODBC,在ODBC治理器中为db1.mdb建一处系统数据源
名称:dbdsn (可以自己定)
驱动程序:Microsoft Access Driver (*.MDB)

代码:
...
$Conn = odbc_connect("dbdsn","admin","123"); //连接数据源
$Doquery=odbc_exec($Conn,"select * from 表名 where 条件");//执行查询
...


第二种方式是ADO
...
$conn=new COM("ADODB.Connection");
$dsn="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=".realpath("path/db1.mdb");
$conn->open($dsn);
$sql="select * from 表名 where 条件";
$ru=$conn->Execute($sql);

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