PDO封装
Posted 颠覆整个世界
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PDO封装相关的知识,希望对你有一定的参考价值。
<?php class PDOA { public $host = "localhost"; public $uid = "root"; public $pwd = ""; //执行SQL语句的方法,$type代表SQL语句的类型,0代表查询 public function Prepare($sql,$typepdo = 0,$db = "mydb",$fwq = "mysql") { $dsn = "$fwq:dbname=$db;host=$this->host"; $pdo = new PDO($dsn,$this->uid,$this->pwd); $stm = $pdo->prepare($sql); if($stm->execute()) { if($typepdo == 0) { return $stm->fetchAll(PDO::FETCH_ASSOC); } else { echo "执行成功"; return $stm->execute(); } } else { echo "执行失败"; } } }
以上是关于PDO封装的主要内容,如果未能解决你的问题,请参考以下文章