CodeIgniter - how to catch DB errors?
Maybe this:
$db_debug = $this->db->db_debug; //save setting
$this->db->db_debug = FALSE; //disable debugging for queries
$result = $this->db->query($sql); //run query
//check for errors, etc
$this->db->db_debug = $db_debug; //restore setting
Use error()
method:
$this->db->error();
For CodeIgniter 2, you can use the following functions which are now deprecated:
$this->db->_error_message(); (mysql_error equivalent)
$this->db->_error_number(); (mysql_errno equivalent)