0
PDO 데이터베이스 클래스가 있습니다. PDO에 약간 익숙하므로 오류가 발생하면 디버깅 할 수있는 방법을 모릅니다. 나는 단지 오류를 잡아서 요청으로 돌려 보내는 가장 좋은 방법을 알고 싶다.PDO 데이터베이스 클래스에서 오류가 발생했습니다.
class database {
private $dbh;
private $stmt;
public function __construct($user, $pass, $dbname) {
$this->dbh = new PDO(
"mysql:host=localhost;dbname=$dbname",
$user,
$pass,
array(PDO::ATTR_PERSISTENT => true)
);
}
public function query($query) {
$this->stmt = $this->dbh->prepare($query);
return $this;
}
public function bind($pos, $value, $type = null) {
if(is_null($type)) {
switch(true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->stmt->bindValue($pos, $value, $type);
return $this;
}
public function execute() {
return $this->stmt->execute();
}
public function resultset() {
$this->execute();
return $this->stmt->fetchAll();
}
public function single() {
$this->execute();
return $this->stmt->fetch();
}
}
감사
관련 항목 : http://stackoverflow.com/questions/3726505/how-to-squeeze-error-message-out-of-pdo –
pekka가 게시 한 링크를 통해 이동하십시오, 그는 대답이 –