0

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.

2
  • Did you see this question? stackoverflow.com/questions/6600125/… Commented Dec 21, 2016 at 3:11
  • Yes I did. The suggested answer that you referenced is to hide all errors for the user. I still want to show some db errors for development purpose. Commented Dec 21, 2016 at 3:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.