我只是嘗試這種代碼:PDO,收到錯誤,如果採取
public function create_account($username, $password, $email) {
$password = sha1($password);
$activation_key = md5($username . $email);
$this->STH = $this->DBH->prepare("INSERT INTO users(username, password, email, activation_key, created) VALUES(:username, :password, :email, :activation_key, :created)");
$this->STH->bindParam(':username', $username);
$this->STH->bindParam(':password', $password);
$this->STH->bindParam(':email', $email);
$this->STH->bindParam(':activation_key', $activation_key);
$this->STH->bindParam(':created', time());
$this->STH->execute();
if ($this->DBH->lastInsertId()) {
//$this->send_mail($username, $email);
return true;
} else {
//Log
}
}
現在它工作,確實如此。但就在一分鐘前,我錯過了a)SQL語句,導致數據未被插入。我嘗試了try {} catch塊 - 但我沒有收到任何錯誤,仍然 - 是否假設是這樣? 我怎樣才能解決這個代碼,正確登錄PDO的錯誤(如果接受)
可能相關:[如何從PDO擠出錯誤消息?](http://stackoverflow.com/q/3726 505) –