我在一种方法中需要PDO的prepare()和execute()......但它没有'工作。 环境:IIS 10 / SQL Server 2014
class dbh extends PDO {
...
public function xquery($sql){
if(($sth = $this->prepare($sql)) === false){
$error_arr = $this->errorInfo();
$this->error .= '<span title="error_code:'.$error_arr[0].'">(prepare) '.$error_arr[1].':'.$error_arr[2].'</span>';
}
if($sth->execute() === false){
$error_arr = $sth->errorInfo();
$this->error .= '<span title="error_code:'.$error_arr[0].'">(execute) '.$error_arr[1].':'.$error_arr[2].'</span>';
}
}
}
通话方法
$sql = "SELECT * FROM table";
$dbh->xquery($sql) OR die($dbh->error);
任何有关的建议!
答案 0 :(得分:0)
发现错误... xquery()应返回$ sth
public function xquery($sql){
if(($sth = $this->prepare($sql)) === false){
$error_arr = $this->errorInfo();
$this->error .= '<span title="error_code:'.$error_arr[0].'">(prepare) '.$error_arr[1].':'.$error_arr[2].'</span>';
}
if($sth->execute() === false){
$error_arr = $sth->errorInfo();
$this->error .= '<span title="error_code:'.$error_arr[0].'">(execute) '.$error_arr[1].':'.$error_arr[2].'</span>';
}
if(empty($this->error))
return $sth;
}