note 75441 deleted from function.mysql-error by tularis

From: Date: Wed, 30 May 2007 12:17:47 +0000
Subject: note 75441 deleted from function.mysql-error by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127029@lists.php.net to get a copy of this message
Note Submitter: splogamurugan at gmail dot com Reason: useless ---- I found a code by "l dot poot at nl dot dk" for sending a error log for the developers. While implementing this, i found that it needs more data. So i added some code to tell about where the error occured using debug_print_backtrace function . Here the code: <?php $b_debugmode = 1; // 0 || 1 $system_operator_mail = 'developer@company.com'; $system_from_mail = 'info@mywebsite.com'; function db_query( $query ){ global $b_debugmode; // Perform Query $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { if($b_debugmode){ $message = '<b>Invalid query:</b><br>' . mysql_error() . '<br><br>'; $message .= '<b>Whole query:</b><br>' . $query . '<br><br>'; die($message); } raise_error('db_query_error: ' . $message); } return $result; } function raise_error( $message ){ global $system_operator_mail, $system_from_mail; $serror= "Env: " . $_SERVER['SERVER_NAME'] . "\r\n" . "timestamp: " . Date('m/d/Y H:i:s') . "\r\n" . "script: " . $_SERVER['PHP_SELF'] . "\r\n" . "error: " . $message ."\r\n\r\n"; //------- added by me ------------- $debug_arr=debug_backtrace(); $str= "-----FROM debug Back trace------------\r\n"; foreach($debug_arr as $index=>$debug_details_arr) { $str .='--- ERROR #'.$index."-----------------\r\n"; foreach($debug_details_arr as $index2=> $debug_details_msg) { if($index2!='args') $str .= $index2.': '.$debug_details_msg."----\r\n"; else { $str .="--With Args-------\r\n"; foreach($debug_details_msg as $index3=>$context_arr_value) $str .= $index3.'=>'.$context_arr_value."\r\n"; $str .="------------------\r\n"; } } } $str .="--------------------------------\r\n"; $str .="\r\n----FROM mysql error-----------\r\n"; $str .= mysql_error(); $str .="\r\n--------------------------------\r\n"; //------------------------------------- // open a log file and write error $fhandle = fopen( '/logs/errors'.date('Ymd').'.txt', 'a' ); if($fhandle){ fwrite( $fhandle, $serror ); fclose(( $fhandle )); } // e-mail error to system operator if(!$b_debugmode) mail($system_operator_mail, 'error: '.$message.''.$str, $serror, 'From: ' . $system_from_mail ); } ?>

« previous php.notes (#127029) next »