I am developing a website in codeigniter. My problem is as,
In the development environment (db_debug = TRUE). It throws error, If I provide data with an entry with the existing value in primary key.
What I wanted to do is, when a query fails by following reasons: duplicate, foreign key violation etc., in the development environment instead of displaying the error, I want to return result: true and message: query failed for some reason from the model.
How can achieve this?
I am testing with following code,
$test_query = $this->db->query("INSERT INTO test SET id = 1, email = '[email protected]'");
$out = array();
if($test_query) {
// do other queries and get data
$out['data'] = 'some data from other subsequent database query';
$out['msg'] = 'query failed for some reason';
$out['result'] = true;
}
else {
$out['result'] = false;
// fails
}
return $out;
Note: I want to skip only predicted / mostly occurred / basic errors for example duplicate, foreign key violation, primary key violation etc. even if in the development mode, being aware of possible errors while still in development environment.
I can not use db_debug = FALSE because I still want to be aware of other possible db related query failures so that I can fix those errors while developing the application. The reason I want to skip my specified error is, I don't want to break the system flow with these predictable errors.