application/config/database.php db_debug = FALSE
// to show the error message with 500 error
$db['default'] = array(
'db_debug' => (ENVIRONMENT !== 'production'),
);
// to catch the error messages in the php model failure condition.
$db['default'] = array(
'db_debug' => FALSE,
);
----------------------
// keep this code in the else condition and this code will return the database error.
$error = $this->db->error();
$this->db->trans_rollback();
return $error;
------------------------
//Inside the model
// executed query.
$b_query = $this->db->insert('project_mn', $data);
// if any errors then it will display the error message.
if(!@$this->db->query($b_query))
{
$error = $this->db->error();
return $error;
// do something in error case
}else{
return "Success";
// do something in success case
}