note 80206 added to function.trigger-error

From: Date: Fri, 04 Jan 2008 07:11:31 +0000
Subject: note 80206 added to function.trigger-error
Groups: php.notes 
Request: Send a blank email to php-notes+get-134757@lists.php.net to get a copy of this message
We wanted to be able to pass an SQL query to the error handler on our site so we could monitor SQL problems, you cant do this through normal methods so we came up with this bridge script that 100% works <?php function myErrorHandler($errno, $errstr, $errfile, $errline){ switch ($errno) { case E_USER_ERROR: if ($errstr == "(SQL)"){ // handling an sql error echo "<b>SQL Error</b> [$errno] " . SQLMESSAGE . "<br />\n"; echo "Query : " . SQLQUERY . "<br />\n"; echo "On line " . SQLERRORLINE . " in file " . SQLERRORFILE . " "; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; } else { echo "<b>My ERROR</b> [$errno] $errstr<br />\n"; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n"; echo "Aborting...<br />\n"; } exit(1); break; case E_USER_WARNING: case E_USER_NOTICE: } /* Don't execute PHP internal error handler */ return true; } // function to test the error handling function sqlerrorhandler($ERROR, $QUERY, $PHPFILE, $LINE){ define("SQLQUERY", $QUERY); define("SQLMESSAGE", $ERROR); define("SQLERRORLINE", $LINE); define("SQLERRORFILE", $PHPFILE); trigger_error("(SQL)", E_USER_ERROR); } set_error_handler("myErrorHandler"); // trigger an sql error $query = "SELECT * FROM tbl LIMIT 1"; $sql = @mysql_query($query) or sqlerrorhandler("(".mysql_errno().") ".mysql_error(), $query, $_SERVER['PHP_SELF'], __LINE__); ?> ---- Server IP: 194.145.210.3 Probable Submitter: 82.37.208.186 ---- Manual Page -- http://www.php.net/manual/en/function.trigger-error.php Edit -- https://master.php.net/note/edit/80206 Del: integrated -- https://master.php.net/note/delete/80206/integrated Del: useless -- https://master.php.net/note/delete/80206/useless Del: bad code -- https://master.php.net/note/delete/80206/bad+code Del: spam -- https://master.php.net/note/delete/80206/spam Del: non-english -- https://master.php.net/note/delete/80206/non-english Del: in docs -- https://master.php.net/note/delete/80206/in+docs Del: other reasons-- https://master.php.net/note/delete/80206 Reject -- https://master.php.net/note/reject/80206 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134757) next »