|
2009-11-17, 06:12 PM | #1 |
注册日期: 2003-10-22
帖子: 11,053
积分:6
精华:24
现金:14348金币
资产:29325305金币
|
php 连接 access
第一种方式是用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); ... -------------------------------------------------------------------------------------------- <?PHP //创建ADO连接 $conn = @new COM("ADODB.Connection") or die ("ADO连接失败!"); $c . realpath("db1.mdb"); $conn->Open($connstr); //创建记录集查询 $rs = @new COM("ADODB.RecordSet"); $rs->Open("select * from info",$conn,1,3); ?> <table border=1> <tr> <td>ID</td> <td>NAME</td> <td>text</td> </tr> <?php while(!$rs->eof){ ?> <tr> <td><?php echo $rs->Fields["ID"];?></td> <td><?php echo $rs->Fields["NAME"];?></td> <td><?php echo $rs->Fields["text"];?></td> </tr> <?php $rs->Movenext(); } $rs->close(); ?> </table> 第三种方法:pdo$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=d:/program files/Apache Software Foundation/Apache2.2/htdocs/filesupload/db/filesupload.mdb"); |
|