<?phpfunction myErrorHandler($errno, $errstr, $errfile, $errline){switch ($errno) {case E_USER_ERROR:if ($errstr == "(SQL)"){// handling an sql errorecho "<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 handlingfunction 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__);?>
添加回答
举报
0/150
提交
取消