包含PDO用法的类
<?php class DB { public $host = "localhost"; public $uid = "root"; public $pwd = ""; public function Query($sql,$type=0,$db="mydb") { $d = new MySQLi($this->host,$this->uid,$this->pwd,$db); !mysqli_connect_error() or die("连接失败!"); $result = $d->query($sql); if($result) { if($type==0) { return $result->fetch_all(); } else { echo "执行成功!"; return $result; } } else { echo "执行失败!"; } } public function Querypdo($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_NUM); } else { echo "执行成功!"; return $stm->execute(); } } else { echo "执行失败!"; } } }