Jump to content

[SOLVED] displayed errors sent to database


EchoFool

Recommended Posts

Hey,

 

Quick question, is there a way to stop errors from displaying and put them into a mysql INSERT query which inserts into my database for me to deal with in a bug page that i coded myself....

 

im referring to all kind of php errors/mysql errors... can php be set up to do this or is it not possible (include syntax errors)

 

Just curious, because im aming to make a system that saves bugs automatically for staff to deal with, its more efficient than waiting on users to bug report it.

You should probably write database errors to a log file - http://us2.php.net/manual/en/function.error-log.php Because if you are experiencing errors due to problems with your database, you likely won't be able to store the errors in the database, whereas the file system would be available if your web site is functional at all.

function store_errors($error_level, $error_message, $error_file, $error_line, $error_context){
     $insert = mysql_query("INSERT INTO `table` (`error_level`, `error_message`, `error_file`, `error_line`, `error_context`) VALUES ('$error_level', '".mysql_escape_string($error_message)."', '".mysql_escape_string($error_file)."', '".mysql_escape_string($error_line)."', '".mysql_escape_string($error_context)."')");
}

set_error_handler("store_errors");

//this of course implies that you've created a MySQL table called "table" with 5 fields (error_level, error_message, error_file, error_line, error_context)

function store_errors($error_level, $error_message, $error_file, $error_line, $error_context){
     $insert = mysql_query("INSERT INTO `table` (`error_level`, `error_message`, `error_file`, `error_line`, `error_context`) VALUES ('$error_level', '".mysql_escape_string($error_message)."', '".mysql_escape_string($error_file)."', '".mysql_escape_string($error_line)."', '".mysql_escape_string($error_context)."')");
}

set_error_handler("store_errors");

//this of course implies that you've created a MySQL table called "table" with 5 fields (error_level, error_message, error_file, error_line, error_context)

 

Good point PFMaBiSmAd how do i get database errors to go to a log file?

 

And thanks for the function suggestion... does "store_errors" automatically mean it has those 5 settings in that store_errors name?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.