E-mail alerts on mysql query errors

I’ve started changing how I run DB queries in PHP now to include error reporting (which is e-mailed to me.)

It’s pretty simple and only has two parts. Here is where I run the query and call my reporting function if it fails:

$result = mysql_query($sql) or die(reportDatabaseError($sql,mysql_error()));

Here’s my reporting function:

function reportDatabaseError($query,$error) {
$message = "URL = ".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."
QUERY = $query
ERROR = $error";
mail("myemail@domain.com",$_SERVER['HTTP_HOST']." MySQL error report",$message,$header);
return $error;

Nothing too fancy, but now I get an e-mail when a DB query fails. So far, I’ve found a couple of bugs on the one site where I’m testing this. I’ve also found that there are a few sites that have bad links to my site, which I’ve been able to compensate for in my php or with mod_rewrite.