+// Functions which interact with the database
+LOAD_INC_ONCE("inc/mysql-manager.php");
+
+// Load extensions and language
+LOAD_INC_ONCE("inc/extensions.php");
+
+// Load database library
+LOAD_INC_ONCE("inc/db/lib.php");
+
+// Error handler function
+function __errorHandler ($errno, $errstr, $errfile, $errline) {
+ // Construct message
+ $msg = sprintf("errno=%s,errstr=%s,errfile=%s,errline=%s",
+ $errno,
+ $errstr,
+ basename($errfile),
+ $errline
+ );
+
+ // Write debug log message
+ DEBUG_LOG(__FUNCTION__, __LINE__, "".$msg, true);
+
+ // Output message to user and die
+ if (EXT_IS_ACTIVE("debug")) {
+ // Debug extension found! So Output a small message
+ mxchange_die("Error message written to debug.log. Please try to call <a href=\"{!URL!}\">the main page</a> to continue.");
+ } else {
+ // No debug extension found, so regular output
+ debug_report_bug($msg);
+ }
+}
+
+// Set error handler
+set_error_handler('__errorHandler');
+
+// Call-back function for running shutdown functions and close database connection
+function __SHUTDOWN_HOOK () {
+ global $link;
+
+ // Call the filter chain 'shutdown'
+ RUN_FILTER('shutdown', null, false);
+
+ if (is_resource($link)) {
+ // Close link
+ SQL_CLOSE($link, __FILE__, __LINE__);
+ } else {
+ // No database link
+ addFatalMessage(getMessage('NO_DB_LINK'));
+ }
+}
+
+// Register shutdown hook
+register_shutdown_function('__SHUTDOWN_HOOK');