Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.