CodeIgniter – how to catch DB errors?

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)

Leave a Comment