MySQL Forums
Forum List  »  PHP

Automatic notification of errors with your MySQL database
Posted by: Dave Walker
Date: August 29, 2005 04:50AM

This weekend I a bad experience with a corrupt table, luckily I was automatically notified by a function I had added to the most import PHP scripts on my site. This saved me hours of diagnosis time and possible downtime (I would have been unaware of the error for days).

Its quite simple and can be added in just a few minutes:

function reportMySQLError($email, $MySQLError, $TheQuery)
{
mail($email,
"WARNING: Error running one of the MySQL queries on site!.",
"The SQL Error was: $TheSQLError The query was: $TheQuery",
"From: $email\nReply-To: $email");
}
...
THEN IN LATER in your code:
...
$result = mysql_query($the_query);
if (!$result) reportMySQLError($email, mysql_error(), $the_query);

Full details here:
http://dwalker.co.uk/forum/viewtopic.php?p=1413

I wish you all prosperity in health and wealth.

Dave

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.