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