這篇文章主要介紹了PHP數據庫鏈接類(PDO+Access),有需要的朋友可以參考一下
PHP PDO Access鏈接 代碼如下: class DbHelpClass { private $conn; private $qxId; private $ret; function __construct() { $path="../../App_Data/sd#f#45G_!.mdb"; $constr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".realpath($path); $this->conn= new PDO("odbc:$constr") or die ("PDO Connection faild."); } /*讀取*/ function Read($sql,$params=array()) { $bind=$this->conn->prepare($sql); $arrKeys=array_keys($params); foreach($arrKeys as $row) { $bind->bindValue(":".$row,$params[$row]); } $bind->execute() or die('sql error:'.$sql); $result=$bind->fetchAll(); return $result; } /*添加,修改需調用此方法*/ function Edit($sql,$params=array()) { $bind=$this->conn->prepare($sql); $arrKeys=array_keys($params); foreach($arrKeys as $row) { $bind->bindValue(":".$row,$params[$row]); } $a=$bind->execute() or die('sql error'); return $a; } } $dbh =new DbHelpClass();