首页 >后端开发 >php教程 >PHP数据库链接类(PDO+Access)实例分享_PHP教程

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

WBOY
WBOY原创
2016-07-13 17:17:55859浏览

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/621697.htmlTechArticlePHP PDO Access链接 复制代码 代码如下: class DbHelpClass { private $conn; private $qxId; private $ret; function __construct() { $path="../../App_Data/sd#f#45G_!.mdb"; $con...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn