case "sqlite": $db = new DB_SQLite(); break; case "pgsql": $db = new DB_PgSQL(); break; case "mysqli": $db = new DB_MySQLi(); break; default: $db = new DB_MySQL(); } // Connect to Database define('TABLE_PREFIX', $config['database']['table_prefix']); $db->connect($config['database']); $db->set_table_prefix(TABLE_PREFIX); $db->type = $config['database']['type']; // Load Settings if (file_exists(MYBB_ROOT . "inc/settings.php")) { require_once MYBB_ROOT . "inc/settings.php"; } if (!file_exists(MYBB_ROOT . "inc/settings.php") || !$settings) { if (function_exists('rebuild_settings')) { rebuild_settings(); } else { $options = array("order_by" => "title", "order_dir" => "ASC"); $query = $db->simple_select("settings", "value, name", "", $options); while ($setting = $db->fetch_array($query)) { $setting['value'] = str_replace("\"", "\\\"", $setting['value']); $settings[$setting['name']] = $setting['value']; }
/** * @param array $config * * @return DB_MySQL|DB_MySQLi|DB_PgSQL|DB_SQLite */ function db_connection($config) { require_once MYBB_ROOT . "inc/db_{$config['database']['type']}.php"; switch ($config['database']['type']) { case "sqlite": $db = new DB_SQLite(); break; case "pgsql": $db = new DB_PgSQL(); break; case "mysqli": $db = new DB_MySQLi(); break; default: $db = new DB_MySQL(); } // Connect to Database define('TABLE_PREFIX', $config['database']['table_prefix']); $db->connect($config['database']); $db->set_table_prefix(TABLE_PREFIX); $db->type = $config['database']['type']; return $db; }
/** * Runs the shutdown items after the page has been sent to the browser. * */ function run_shutdown() { global $config, $db, $cache, $plugins, $error_handler, $shutdown_functions, $shutdown_queries, $done_shutdown, $mybb; if ($done_shutdown == true || !$config || $error_handler->has_errors) { return; } // Missing the core? Build if (!is_object($mybb)) { require_once MYBB_ROOT . "inc/class_core.php"; $mybb = new MyBB(); // Load the settings require MYBB_ROOT . "inc/settings.php"; $mybb->settings =& $settings; } // If our DB has been deconstructed already (bad PHP 5.2.0), reconstruct if (!is_object($db)) { if (!isset($config) || empty($config['database']['type'])) { require MYBB_ROOT . "inc/config.php"; } if (isset($config)) { require_once MYBB_ROOT . "inc/db_" . $config['database']['type'] . ".php"; switch ($config['database']['type']) { case "sqlite": $db = new DB_SQLite(); break; case "pgsql": $db = new DB_PgSQL(); break; case "mysqli": $db = new DB_MySQLi(); break; default: $db = new DB_MySQL(); } $db->connect($config['database']); define("TABLE_PREFIX", $config['database']['table_prefix']); $db->set_table_prefix(TABLE_PREFIX); } } // Cache object deconstructed? reconstruct if (!is_object($cache)) { require_once MYBB_ROOT . "inc/class_datacache.php"; $cache = new datacache(); $cache->cache(); } // And finally.. plugins if (!is_object($plugins) && !defined("NO_PLUGINS") && !($mybb->settings['no_plugins'] == 1)) { require_once MYBB_ROOT . "inc/class_plugins.php"; $plugins = new pluginSystem(); $plugins->load(); } // We have some shutdown queries needing to be run if (is_array($shutdown_queries)) { // Loop through and run them all foreach ($shutdown_queries as $query) { $db->query($query); } } // Run any shutdown functions if we have them if (is_array($shutdown_functions)) { foreach ($shutdown_functions as $function) { call_user_func_array($function['function'], $function['arguments']); } } $done_shutdown = true; }