Welcome Guest, Not a member yet? Register   Sign In
active record and errors
#1

[eluser]akkumaru[/eluser]
Hi, all,,
I want to know How to catch all kind of possible errors when i'm using Active Record,,

e.g.
How do I know an insertion or update is failed so that I can set up an error handling strategy?
Or How do I know a database error occures while prevent the CI error message to be written to the page, so that I can set up my error handling strategy?

I've tried the try{}catch(Exception $e){} clause,, but it seems it didn't work,,
#2

[eluser]bitist[/eluser]
I modified the DB_driver.php, look for function query( ...

You'll find there this code:
Code:
// grab the error number and message now, as we might run some
// additional queries before displaying the error
$error_no = $this->_error_number();
$error_msg = $this->_error_message();

So the variables $error_no and $error_msg contain the specific mysql error descriptions.
You can use it to write out to a file or just simply create a popup window and display it.

Don't forget to activate the $db['default']['db_debug'] = true; in database.php config file.
#3

[eluser]akkumaru[/eluser]
thank you devpedia,,

but is there any 'safer' way?
i'm new to CI and don't really think I should touch the system folder,,
#4

[eluser]bitist[/eluser]
I don't see other way. In the query function, when an error occure, the display_error() will be called and there is an
Code:
exit();
there.

So you could change only this display_error() function and write a file when an error occure.

It's not a big deal, I've modified this file, I get an email on any error and write a log file too. But fortunately I don't really have errors ;-)
#5

[eluser]akkumaru[/eluser]
,,i see,
i may try this then,,

oh, by the way,,
it seems that i cannot use the database class' transaction like this:

Code:
$this->load->model("model1","",TRUE);
$this->load->model("model2","",TRUE);

$this->db->trans_start();

$this->model1->update($value1);
$this->model2->update($value2);

$this->db->trans_complete();

first update will not be rolled back even when the second is failed..
how to solve this?




Theme © iAndrew 2016 - Forum software by © MyBB