PDO_DB.php[CODE:]
require_once(SET_DB);
final class ExecSQL {
private $conn; //连接对象
private $sth; //操作对象
function __construct(){ //构造函数 连库
try {
$this->conn = new PDO(Base::$DB_DSN, Base::$DB_USER, Base::$DB_PW, Base::$DB_DRIVER_OPTIONS);//建立连接
} catch(PDOException $e) { //捕获异常
print "Error!: " . $e->getMessage() . "
";
die();
}
}
function __destruct() { //析构函数 清空
$this->sth = null;
$this->conn = null;
}
public function SetSQL($sql) { //设置sql语句
$this->sth = $this->conn->prepare($sql);
}
public function bindParam($name, $value) { //绑定参数
$this->sth->bindParam($name, $value);
}
public function Query_noreturn() { //执行并无返回值记录
$this->sth->execute();
}
public function Query() { //返回一维数组
$this->sth->execute();
$RSarray = $this->sth->fetch();
return $RSarray;
}
public function Query_array() { //返回二维数组
$this->sth->execute();
$RSarray = $this->sth->fetchAll();
return $RSarray;
}
public function Inf_right($inf,$url){ //正确提示
if($inf==""){
echo "";
}else{
echo "";
}
}
public function Inf_wrong($inf){ //错误提示
if($inf==""){
echo "";
}else{
echo "";
}
}
public function Compared_file($a,$b){ //如果字符串$a包含$b
$coms = strstr($a,$b); //名对比
if($coms){ //非空则返回TRUE,否则返回FALSE
return true;
}else{
return false;
}
}
}
?>
用了很久了哦,很方便的哦