When I execute this query:
public function delete_user_test($id){
$this->db->trans_begin();
$this->db->where('id',$id);
$this->db->delete($this->user_table);
$person_id = $this->get_user_account($id)['person_id'];
$this->db->where('id',$person_id);
$this->db->delete($this->person_table);
$this->db->trans_complete();
if($this->db->trans_status()===false){
$this->db->trans_rollback();
return $this->db->error();
}else{
$this->db->trans_commit();
return true;
}
}
and dbdebug in the database config file is set to true, I will get a full screen error saying
Error Number: 1451
Cannot delete or update a parent row: a foreign key constraint fails (`database_table`.`acc_codes`, CONSTRAINT `acc_codes_fk` FOREIGN KEY (`user_id`) REFERENCES `user_accounts` (`id`))
DELETE FROM `user_accounts` WHERE `id` = '2'
Filename: models/AccMdl.php
Line Number: 655
How do I get the error message from that page and pass it back in a banner instead of a full page? If I turn dbdebug false, all I get from $this->db->error(); is 0.
Edit
Added my database config stuff.
$db['default'] = array(
'dsn' => '',
'hostname' => host,
'username' => uname,
'password' => pw,
'database' => name,
'dbdriver' => drvr,
'dbprefix' => '',
'pconnect' => FALSE,
// 'db_debug' => (ENVIRONMENT !== 'production'),
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Edit 2
I have managed to get the error out. The method I used was to remove trans_begin and the other transaction items. Is there a way to integrate this with the transaction items?
$this->db->where('id',$id);
if(!$this->db->delete($this->user_table)){
return $this->db->error();
}
This will produce the error message. But how do I combine this with the rest?