Codeigniter returning code 0 db errors without message
The user has mentioned that he wants to get the error in the database transaction. so for that, I found only this solution to the problem, but It is quite verbose:
try { $this->db->trans_begin(); $res = $this->db->where('id',$id)->delete($this->table); if(!$res) throw new Exception($this->db->_error_message(), $this->db->_error_number()); $this->db->trans_commit();}catch (Exception $e) { $this->db->trans_rollback(); log_message('error', sprintf('%s : %s : DB transaction failed. Error no: %s, Error msg:%s, Last query: %s', __CLASS__, __FUNCTION__, $e->getCode(), $e->getMessage(), print_r($this->main_db->last_query(), TRUE)));}
Please note that
- I am using the "manual transaction" mode of CI,
- I have to call
$this->db->_error_message()
,$this->db->_error_number()
after each query, because it returns an empty response in the catch block.
This way you can achieve the detailed error handling.
Here is the reference link.