Outputting All PHP Errors to Database Not Error_Log

Outputting all PHP errors to database not error_log

I don't think it can be done without building an own error handler, but technically, that is the one global change you're looking for.

Modified example from the manual:

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
// you'd have to import or set up the connection here
mysql_query("INSERT INTO error_log (number, string, file, line) ".
"VALUES .....");

/* Don't execute PHP internal error handler */
return true;
}

then

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

Hide error reporting and insert into database

Hiding the error on the web browser - from Turn Off Display Error PHP.ini
At top of php file add:

display_errors(false); 
log_errors(true);

Logging to mysql see the accepted answer at Outputting all PHP errors to database not error_log

PHP error_log errors to MySQL

You can only handle runtime errors with a custom error handler. The echo "foo error in your example happens when parsing (i.e. reading in) the source. Since PHP can not fully parse the code, it can also not run your error handler on this error.



Related Topics



Leave a reply



Submit