0
我在我的类方法中使用try/catch块,如果得到一个异常,我记录错误。但是我想告诉“用户”一个数据库查询/ etc失败 - 这个问题应该尽快解决。 我可以在我的方法中使用异常中的die(),但这不会干,因为我必须重新输入它很多,所以关于如何执行此操作的任何建议。全局php PDO处理错误
实施例方法:
public function login($username, $password) {
try {
$this->STH = $this->DBH->prepare("SELECT id, baned, activated FROM users WHERE username = ? AND password = ?");
$this->STH->setFetchMode(PDO::FETCH_OBJ);
$this->STH->execute(array($username, $password));
if (($row = $this->STH->fetch()) !== false)
return $row;
} catch (PDOException $e) {
//Log $e->getMessage();
die('A database error occoured, we are working on the problem, and it should work in a few...');
}
}
我无法得到它的工作,通过上述的方法,没有结果输出,我做了一个错误故意...... – John
该处理程序将仅被调用为未捕获的异常,因此如果您已经在代码的某处捕获到异常,则应该再次抛出异常,以便全局处理程序可以捕获它。 – rabusmar
我该怎么做 – John