Welcome Guest, Not a member yet? Register   Sign In
Writing errors to database / emailing them

THis is driving me mad now.

Has anyone managed to extend CI's error handling to write all errors to the database and email those bad boys to someone?

You'll have to paste more information if you expect an answer...
What is not working? Do you have code so far%


I would like to send any errors that occur in my application to a database table called errors which will allow me to monitor my application errors using reports.

I was wondering if anyone had extended or knew of an extension to allow this using CI's existing error handling functions.

Thanks Smile

I am new here so there might be something easier, but I think you can easily just use a controller to write to the "log table" where you can record pretty much anything...

Google solves --> Post on StackOverFlow.com:

Make a file MY_Exceptions.php and place it in /application/libraries/:
class MY_Exceptions extends CI_Exceptions {

    function My_Exceptions()

    function log_exception($severity, $message, $filepath, $line)


        $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];

        log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);

        $this->email->from('[email protected]', 'Your Name');
        $this->email->to('[email protected]');
        $this->email->cc('[email protected]');
        $this->email->bcc('[email protected]');

        $this->email->message('Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line);



Untested but might work Smile

add a table in your database as follows:
    -- ----------------------------
    -- Table structure for errores
    -- ----------------------------
    DROP TABLE IF EXISTS `errores`;
    CREATE TABLE `errores` (
      `id` int(11) NOT NULL auto_increment,
      `Severity` varchar(50) default NULL,
      `message` text,
      `filepath` varchar(250) default NULL,
      `line` varchar(250) default NULL,
      PRIMARY KEY  (`id`)
modify the function log_exception($severity, $message, $filepath, $line) as this:
add the following line:
$this->log_execption_db($severity, $message, $filepath, $line);

add the function log_execption_db to the system library
function log_execption_db($severity, $message, $filepath, $line){
        $this->ci =& get_instance();
            $data = array(
               'Severity' => $severity ,
               'message' => $message ,
               'filepath' => $filepath,
               'line' => $line

        $this->ci->db->insert('errores', $data);

And "ya esta", all the errors will be stored in database too. Also we could create a new confi item in our application to determines if we would like to stored the errors in DB, in file or in both.

Theme © iAndrew 2016 - Forum software by © MyBB