Welcome Guest, Not a member yet? Register   Sign In
Retrieve error backtrace
#1

[eluser]iive[/eluser]
I wonder is there any how I can retrieve the stacktrace when there is an error in our php coding or database error?

For example: let's say I have a database error in my Model, can CI trace back on the screen where this error comes from (the model name, the line in the model.php etc...)? Instead of I see the MySql error message and I have to search through my Models to see which of them contains errors..

I hope my question is clear... and I really hope to know the answer..

thanks!
#2

[eluser]iive[/eluser]
I really need help on this and I think this is a good feature in development process.. it saves a lot of times in debugging process.

Anyone can help?
#3

[eluser]gtech[/eluser]
Hello,

I have done a little bit of research on reading this but cannot find a stacktrace within the codeigniter framework. I know there is a debug_backtrace() in php4 / 5 and it works within codeigniter and may be what you want

You need to set db_debug to false in your config file, this will stop the MYSQL error page appearing and halting your application. (rollback needs db_debug to be false)

I have coded my applications to catch all database errors and report them cleanly.
I have mentioned this before in the forums so please forgive me for repeating myself :-S

what I have done is put all db calls into a function wrapper in a db_call model and then you can choose how to handle errors.


models/calldb.php
Code:
function insert($table, $data_array) {
  $res = $this->db->insert($table,$data_array);
  if (!$res) {
      $errNo   = $this->db->_error_number();
      $errMess = $this->db->_error_message();  
  }
  return array('ErrorN'=>$errNo,
                'ErrorM'=>$errMess);
}
...
// need to implement delete update get getwhere etc

you can then handle db errors whenever they occur

Code:
$ret = $this->calldb->insert($table, $data_array, 1);
  if ($ret['ErrorN']) {
    ...... what ever you want to do..., log the error, return it etc.
  }




Theme © iAndrew 2016 - Forum software by © MyBB