note 12056 added to function.mysql-error.php

From: Date: Tue, 20 Mar 2001 19:20:29 +0000
Subject: note 12056 added to function.mysql-error.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-12588@lists.php.net to get a copy of this message
I use the following syntax for error checking,,, and i call a function that emails me the error; this is a huge help in the development process and an invaluable resource for finding out when mysql isn't working properly! $selectQ = mysql_query("SELECT * FROM tablename") or mysqlerror(mysql_errno(),mysql_error()); function mysqlerror ($error1,$error2) { global $webname,$securehome,$remoteaddr,$thispage; $logfile = "/var/log/mysql/" . $webname . ".err"; $log_err = date("D M j,Y h:i:sA") . " $remoteaddr $error1 $error2 $webname $webhome/$thispage\n"; //determine lastlog time $lastlog = filemtime($logfile); $lasttime = date("Ymdhis",$lastlog); //open-write-close logfile $fp = fopen($logfile,"a+"); fwrite($fp,$log_err); fclose($fp); //calculate time difference in lastlog, send email if greater than 10 seconds $timediff = date("Ymdhis") - $lasttime; if ($timediff > 10) { //SEND EMAIL $err_msg = "WARNING: Check log file if suspected recurrent error!\n\n"; $err_msg .= "Error Occured @:\n"; $err_msg .= date ("D M j, Y h:i:s A") . "\n\n"; $err_msg .= "MySQL ErrNo: $error1\n"; $err_msg .= "MySQL ErrMsg: $error2\n\n"; $err_msg .= "Website: $webname\n"; $err_msg .= "Securehome: $securehome\n"; $err_msg .= "Error Occured on: $thispage\n"; $err_msg .= "Remote IP Access from: $remoteaddr\n"; mail("marc@essoc.com", "$webname - MySQL Error: $error1 - $error2",$err_msg,"From: mysql_err@$webname.com"); } exit; } if you notice above, i created a logfile that keeps track of the errors, just in case something goes wrong; if you sent an email with every error, it could take down your whole server,,, i did once! http://www.php.net/manual/en/function.mysql-error.php

« previous php.notes (#12588) next »