PHP lets you specify you own error handler - set_error_handler()
.
function error_handler($errno, $errstr, $errfile, $errline) {
global $db; //naughty use of global. You could re-create your database connection here instead.
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
$error = 'Notice';
break;
case E_WARNING:
case E_USER_WARNING:
$error = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$error = 'Fatal Error';
break;
default:
$error = 'Unknown';
break;
}
$db->query('INSERT INTO ...'); // create error log here
return true;
}
// Error Handler
set_error_handler('error_handler');
The parameters used in my custom function above have the same names as the manual:
$errno The first parameter, errno, contains the level of the error
raised, as an integer.
$errstr The second parameter, errstr, contains
the error message, as a string.
$errfile The third parameter is
optional, errfile, which contains the filename that the error was
raised in, as a string.
$errline The fourth parameter is optional,
errline, which contains the line number the error was raised at, as an
integer.
Using these parameters you should be able to determine what the error was, what file it was in, and what line it occured on.