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();