What I want to do is something like this:
我想做的是這樣的:
function registerUser($username, $password){
$this->db->insert('tblUsers', array('username'=>$username, 'password'=>md5($password)));
if($this->db->_error_number()==1062){
return "DUPLICATE";
}
return true;
}
However, at the moment if there is a duplicate key then its not letting me get to the _error_number() bit. Its displaying an error like this:
但是,如果有一個重復的密鑰,那么它不會讓我到達_error_number()位。它顯示如下錯誤:
How do I stop codeigniter from bailing with an error and passing the error number to me to deal with appropriately?
如何讓codeigniter停止出錯並將錯誤號傳遞給我以便妥善處理?
Thanks
謝謝
2 个解决方案
#1
12
You can access MySQL error messages in Codeigniter using:
您可以使用以下命令訪問Codeigniter中的MySQL錯誤消息:
$this->db->_error_message();
Apparently DB_DEBUG needs to be set to false in the database config file:
顯然,數據庫配置文件中需要將DB_DEBUG設置為false:
Ensure DB_DEBUG is set to FALSE in the database config file, or execution will halt when a mysql error occurs (it does not get thrown, it justs exits from the php interpreter)
確保DB_DEBUG在數據庫配置文件中設置為FALSE,否則執行將在發生mysql錯誤時停止(它不會被拋出,它只是從php解釋器退出)
鏈接:http://codeigniter.com/forums/viewthread/79950/#413830
#2
8
Suggestion:
建議:
$orig_db_debug = $this->db->db_debug;
$this->db->db_debug = FALSE;
RUN QUERY HERE
$this->db->db_debug = $orig_db_debug;