i have the following code...
(functions.php)
$result = mysql_query($sql) or die(mysql_error($result)."
query: ".$sql);
(init.php)
set_error_handler("custom_
error_hand
ler");
// custom error handler to report our problems
function custom_error_handler($erro
r_level,$e
rror_messa
ge,$error_
file,$erro
r_line,$er
ror_contex
t) {
switch ($error_level){
case 2:
$error_report="E_WARNING : Non-fatal run-time errors. Execution of the script is not halted";
break;
case 8:
$error_report="E_NOTICE : Run-time notices. The script found something that might be an error, but could also happen when running a script normally";
break;
case 256:
$error_report="E_USER_ERRO
R : Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()";
break;
case 512:
$error_report="E_USER_WARN
ING : Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()";
break;
case 1024:
$error_report="E_USER_NOTI
CE : User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()";
break;
case 4096:
$error_report="E_RECOVERAB
LE_ERROR : Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())";
break;
case 8191:
$error_report="E_ALL : All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)";
break;
}
$temp_user=$_SESSION['user
_username'
];
$temp_ip=$_SERVER['REMOTE_
ADDR'];
$error_display="
<b>Error Type:</b> [$error_level] $error_report.<br />
<b>Error Message:</b> $error_message<br />
<b>Filename: $error_file</b> <br />
Line #:$error_line<br />
Context: $error_context<br />
User: $temp_user<br />
IP: $temp_ip<br />
";
db_connect();
// get current time minus time limit to see if its ok to send another email error
$temp_time=time();
$sql="INSERT INTO error_time SET error_timestamp=$temp_time
, error_text='".db_string_my
sqlsafe($e
rror_displ
ay)."'";
$insert = mysql_query($sql);
// prevent email flooding, check for errors in past hour or so otherwise send an email
$sql="SELECT count(*) as c FROM error_time WHERE (UNIX_TIMESTAMP(now()) - 3600 ) <= error_timestamp";
$result = mysql_query($sql);
if ($row=mysql_fetch_array($r
esult)){
$count=$row['c'];
}
if($count==0 || $count=='0'){
//print $error_display;
error_log("Site errored, check error logs",1, "me@me.com","From: webmaster@me.com\nsubject :Site ERROR\nContent-Type: text/html; charset=ISO-8859-1");
}
}
The problem is when the $result fails it doesnt log the actual mysql query it just tells me i have an error on that line. When a sql query errors how can I log the actual query so i can fix it??
Start Free Trial