19c01-2.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 35 行
PHP
35 行
<?php// Define a custom error handler that will save all errors into a database.function db_err_handler($errno, $errstr, $errfile, $errline, $errcontext) { // Open a fresh database connection for this, don't want to reuse // any that might have caused the original error. $db = @mysql_connect('localhost', 'my_user', 'my_password') or die('Error Logging DB Failure: ' . mysql_error()); mysql_select_db('my_database'); // Now, we need to serialize the error context to store it, since it's // a huge array holding all of the variables that exist. $ized = serialize($errcontext); // Ok, we should now be able to insert this error into the table. mysql_query(" insert into error_log (errno, errstr, errfile, errline, errcontext) values ({$errno}, '{$errstr}', '{$errfile}', {$errline}, '{$ized}') "); // Go ahead and close the database connection. mysql_close($db); // Now, if this was a fatal error of some sort, just output 'ERROR' // and kill the process. Otherwise, let it go on as if it didn't happen // The only two of these that we will see, are ERROR or USER_ERROR if (($errno == E_ERROR) || ($errno == E_USER_ERROR)) { die("ERROR"); }}// Now go ahead and register this as the error handler:set_error_handler('db_err_handler');?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?