欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP数据库链接类(PDO+Access)实例分享

程序员文章站 2022-07-03 12:27:54
php pdo access链接 复制代码 代码如下:class dbhelpclass    {   &nb...

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