note 98535 modified in mysqli.query by danbrown

From: Date: Mon, 21 Jun 2010 23:19:20 +0000
Subject: note 98535 modified in mysqli.query by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170355@lists.php.net to get a copy of this message
I like to save the query itself in a log file, so that I don't have to worry about whether the site is live. For example, I might have a global function: <?php function UpdateLog ( $string , $logfile ) { $fh = fopen ( $logfile , 'a' ); $fwrite ( $fh , strftime ('%F %T %z')." ".$string."\n"; fclose ( $fh ); } ?> Then in my mysql function error trapper, something like this: <?php $error_msg = "Database error in [page].php / "; $error_msg .= mysqli_error ( $link )." / "; $error_msg .= $query; UpdateLog ( $error_msg , DB_ERROR_LOG_FILE ); ?> I also include the remote IP, user agent, etc., but I left it out of these code samples. And have it e-mail me when an error is caught, too. Jeff --was-- To add to what Jon (jcwebb) said below, I also like to save the query itself. But I put it into a log file, so that I don't have to worry about whether the site is live. For example, I might have a global function: function UpdateLog ( $string , $logfile ) { $fh = fopen ( $logfile , 'a' ); $fwrite ( $fh , strftime ('%F %T %z')." ".$string."\n"; fclose ( $fh ); } Then in my mysql function error trapper, something like this: $error_msg = "Database error in [page].php / "; $error_msg .= mysqli_error ( $link )." / "; $error_msg .= $query; UpdateLog ( $error_msg , DB_ERROR_LOG_FILE ); I also include the remote IP, user agent, etc., but I left it out of these code samples. And have it e-mail me when an error is caught, too. Jeff http://php.net/manual/en/mysqli.query.php

« previous php.notes (#170355) next »