PHP数据库链接类(PDO+Access)_PHP教程

WBOY
发布: 2016-07-13 17:16:55
原创
870 人浏览过

PHP PDO Access链接

<span class</span><span  DbHelpClass
    {
        </span><span private</span> <span $conn</span><span ;
        </span><span private</span> <span $qxId</span><span ;
        </span><span private</span> <span $ret</span><span ;
        
        </span><span function</span><span  __construct()
        {
            </span><span $path</span>="../../App_Data/sd#f#45G_!.mdb"<span ;
            </span><span $constr</span>="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=".<span realpath</span>(<span $path</span><span ); 
            </span><span $this</span>->conn= <span new</span> PDO("odbc:<span $constr</span>") or <span die</span> ("PDO Connection faild."<span );

        }
        
        </span><span /*</span><span 读取</span><span */</span>
        <span function</span> Read(<span $sql</span>,<span $params</span>=<span array</span><span ())
        {
            </span><span $bind</span>=<span $this</span>->conn->prepare(<span $sql</span><span );
            </span><span $arrKeys</span>=<span array_keys</span>(<span $params</span><span );
            </span><span foreach</span>(<span $arrKeys</span> <span as</span> <span $row</span><span )
            {
                </span><span $bind</span>->bindValue(":".<span $row</span>,<span $params</span>[<span $row</span><span ]);
            }
            </span><span $bind</span>->execute() or <span die</span>('sql error:'.<span $sql</span><span );
            </span><span $result</span>=<span $bind</span>-><span fetchAll();
            
            </span><span return</span> <span $result</span><span ;
        }
        
        </span><span /*</span><span 添加,修改需调用此方法</span><span */</span>
        <span function</span> Edit(<span $sql</span>,<span $params</span>=<span array</span><span ())
        {
            </span><span $bind</span>=<span $this</span>->conn->prepare(<span $sql</span><span );
            </span><span $arrKeys</span>=<span array_keys</span>(<span $params</span><span );
            </span><span foreach</span>(<span $arrKeys</span> <span as</span> <span $row</span><span )
            {
                </span><span $bind</span>->bindValue(":".<span $row</span>,<span $params</span>[<span $row</span><span ]);
                
            }
            
            </span><span $a</span>=<span $bind</span>->execute() or <span die</span>('sql error'<span );
            </span><span return</span> <span $a</span><span ;
        }
    }
    </span><span $dbh</span> =<span new</span> DbHelpClass();
登录后复制

调用:

<span $dbh</span>->Read('select title from pro where id=:id',<span array</span>(id=>1));
登录后复制

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/626675.htmlTechArticlePHP PDO Access链接 ="../../App_Data/sd#f#45G_!.mdb" ="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". ( -conn= PDO("odbc: ") or ("PDO Connection faild." Read( , = = -conn-prepar...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板