connect_error) { $detail = 'connect error (' . $db->connect_errno . ') ' . $db->connect_error; $db = NULL; db_fail($detail); } return TRUE; } else return FALSE; } else if ($state == 'close') { if ($db) { $db->close(); $db = NULL; return TRUE; } else return FALSE; } } /* * Stop the page after a database error. The details, with the file and * line of the failed call, go to the PHP error log; the visitor only * sees a short apology. */ function db_fail($detail = NULL) { global $db; if ($detail === NULL) $detail = $db ? $db->error : 'no database connection'; $caller = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]; error_log('xxx: database error at ' . basename($caller['file']) . ':' . $caller['line'] . ': ' . $detail); if (!headers_sent()) header('HTTP/1.1 500 Internal Server Error'); die('
Sorry, something went wrong. Please try again later.
'); } ?>