<?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 "执行失败"; } } }
时间: 2024-11-09 05:52:14