Note that there are some explanatory texts on larger screens.

plurals
  1. PODB query error while Error Handling
    primarykey
    data
    text
    <p>I wrote the following snippet in order to handle errors.</p> <p><em>(Page.php gets included in index page through : array( falseNamePage=> page.php, ....ect))</em></p> <p>Perfoming some tests to see how it reacts, I delete a page.php from public_html.</p> <p>RESULT :</p> <p>-error logging ok</p> <p>-alert email sending ok</p> <p>-recording in DB : ERROR : </p> <p><strong>Notice</strong>: Undefined variable: $database in /home/.../public_html/index.php on line 40 </p> <p><strong>Warning</strong>: mysql_query() expects parameter 2 to be resource, null given in /home/.../public_html/index.php on line 40 "impossible to connect with DB2"</p> <p>I do not understands why it fails connecting to the DB in this case and sends back an error.</p> <p>DB Connection works fine in every other cases ( delete, select,update, insert ...)</p> <pre><code>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"); </code></pre> <hr> <p><strong>The final question is :</strong></p> <p>WHY IS AN INCLUDE ERROR ECHOED 4 TIMES ?</p> <p>Does the system attempts 4 times to "open stream"?</p> <p>I did :</p> <pre><code>function errorHandler($errno, $errstr, $errfile, $errline) { if ($errno == E_NOTICE ) { echo "&lt;br/&gt;".$errno."== E_NOTICE&lt;br/&gt;";} if ($errno == E_USER_NOTICE) { echo "&lt;br/&gt;".$errno."== E_USER_NOTICE&lt;br/&gt;";} if ($errno == E_DEPRECATED) { echo "&lt;br/&gt;".$errno."== E_DEPRECATED&lt;br/&gt;";} if ($errno == E_USER_DEPRECATED) { echo "&lt;br/&gt;".$errno."== E_USER_DEPRECATED&lt;br/&gt;";} if ($errno == E_STRICT) { echo "&lt;br/&gt;".$errno."== E_STRICT&lt;br/&gt;";} if ($errno == E_WARNING) { echo "&lt;br/&gt;".$errno."== E_WARNING&lt;br/&gt;";} if ($errno == E_USER_WARNING) { echo "&lt;br/&gt;".$errno."== E_USER_WARNING&lt;br/&gt;";} if ($errno == E_ERROR) { echo "&lt;br/&gt;".$errno."== E_ERROR&lt;br/&gt;";} if ($errno == E_USER_ERROR) { echo "&lt;br/&gt;".$errno."== E_USER_ERROR&lt;br/&gt;";} } set_error_handler("errorHandler"); </code></pre> <p>RESULT :</p> <p>2== E_WARNING</p> <p>2== E_WARNING</p> <p>2== E_WARNING</p> <p>2== E_WARNING</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload