I wrote the following snippet in order to handle errors.
(Page.php gets included in index page through : array( falseNamePage=> page.php, ....ect))
Perfoming some tests to see how it reacts, I delete a page.php from public_html.
RESULT :
-error logging ok
-alert email sending ok
-recording in DB : ERROR :
Notice: Undefined variable: $database in /home/.../public_html/index.php on line 40
Warning: mysql_query() expects parameter 2 to be resource, null given in /home/.../public_html/index.php on line 40 "impossible to connect with DB2"
I do not understands why it fails connecting to the DB in this case and sends back an error.
DB Connection works fine in every other cases ( delete, select,update, insert ...)
function errorHandler($errno, $errstr, $errfile, $errline)
{
require_once('connection.php');
$now = time();
$date = date("Y-m-d H:i:s",$now);
switch ($errno) {
case E_NOTICE:
case E_USER_NOTICE:
case E_DEPRECATED:
case E_USER_DEPRECATED:
case E_STRICT:
............ 5 first cases code...............
case E_WARNING:
case E_USER_WARNING:
$message_warning = "Warning : ".$errno." : ".$errstr." : ".$errfile." : ".$errline;
error_log ( $message_warning ,0);
$mail = 'my_mail@yahoo.com'; $sujet = $message_warning; $body_warning = $date." : ".$message_warning;
mail($mail,'=?UTF-8?B?'.base64_encode($sujet).'?=',stripslashes($body_warning));
$query_warning =" INSERT INTO errorlog (severity,errno,errstr,errfile,errline,time)
VALUES ('WARNING','".$errno."','".$errstr."','".$errfile."','".$errline."','".$date."')";
$result_warning = mysql_query($query_warning,$database) or die("impossible to connect with DB2");
break;
case E_ERROR:
case E_USER_ERROR:
............... 2 last cases code ..........
}
}
set_error_handler("errorHandler");
The final question is :
WHY IS AN INCLUDE ERROR ECHOED 4 TIMES ?
Does the system attempts 4 times to "open stream"?
I did :
function errorHandler($errno, $errstr, $errfile, $errline)
{
if ($errno == E_NOTICE )
{ echo "<br/>".$errno."== E_NOTICE<br/>";}
if ($errno == E_USER_NOTICE)
{ echo "<br/>".$errno."== E_USER_NOTICE<br/>";}
if ($errno == E_DEPRECATED)
{ echo "<br/>".$errno."== E_DEPRECATED<br/>";}
if ($errno == E_USER_DEPRECATED)
{ echo "<br/>".$errno."== E_USER_DEPRECATED<br/>";}
if ($errno == E_STRICT)
{ echo "<br/>".$errno."== E_STRICT<br/>";}
if ($errno == E_WARNING)
{ echo "<br/>".$errno."== E_WARNING<br/>";}
if ($errno == E_USER_WARNING)
{ echo "<br/>".$errno."== E_USER_WARNING<br/>";}
if ($errno == E_ERROR)
{ echo "<br/>".$errno."== E_ERROR<br/>";}
if ($errno == E_USER_ERROR)
{ echo "<br/>".$errno."== E_USER_ERROR<br/>";}
}
set_error_handler("errorHandler");
RESULT :
2== E_WARNING
2== E_WARNING
2== E_WARNING
2== E_WARNING