0

I want to catch database error like (Duplicate values or error number 1062 or 1451 ) in codeigniter then return it out. Please help me for this problem. * Sorry for bad English *

public function delete($id){
  $this->db->where('pro_img_id', $id);
  $this->db->delete('tb_image');
  if($this->db->_error_number() == 1602){
    return 'duplicate error';
  }else if($this->db->affected_rows() > 0) {
    return 'success';
  } else {
    return false;
  }
}
Vixar
  • 11
  • 6

1 Answers1

0
print_r($query);

You can also use (in view) and you will see the SQL statement:

$this->output->enable_profiler(TRUE);

this is the mysql_error() wrapper.

$this->db->_error_message();

And the mysql_errno wrapper is:

$this->db->_error_number();
Putra L Zendrato
  • 332
  • 3
  • 12