Exemple #1
0
function db_connect($db_data = '')
{
    global $phpbb_root_path, $phpEx, $sql_db, $db, $quickinstall_path, $settings;
    $db_data = empty($db_data) ? $settings->get_db_data() : $db_data;
    list($dbms, $dbhost, $dbuser, $dbpasswd, $dbport) = $db_data;
    // If we get here and the extension isn't loaded it should be safe to just go ahead and load it
    $available_dbms = qi_get_available_dbms($dbms);
    if (!isset($available_dbms[$dbms]['DRIVER'])) {
        trigger_error("The {$dbms} dbms is either not supported, or the php extension for it could not be loaded.", E_USER_ERROR);
    }
    // Instantiate the database
    if (defined('PHPBB_31')) {
        $dbal = substr($available_dbms[$dbms]['DRIVER'], strrpos($available_dbms[$dbms]['DRIVER'], '\\') + 1);
        // Load the appropriate database class if not already loaded.
        if (!class_exists('dbal_' . $dbal . '_qi')) {
            // now the quickinstall dbal extension
            include $quickinstall_path . 'includes/db/31/' . $dbal . '.' . $phpEx;
        }
        $sql_db = 'dbal_' . $dbal . '_qi';
    } else {
        // Load the appropriate database class if not already loaded.
        if (!class_exists('dbal_' . $available_dbms[$dbms]['DRIVER'] . '_qi')) {
            // phpBB dbal class.
            include $phpbb_root_path . 'includes/db/' . $available_dbms[$dbms]['DRIVER'] . '.' . $phpEx;
            // now the quickinstall dbal extension
            include $quickinstall_path . 'includes/db/' . $available_dbms[$dbms]['DRIVER'] . '.' . $phpEx;
        }
        $sql_db = 'dbal_' . $available_dbms[$dbms]['DRIVER'] . '_qi';
    }
    $db = new $sql_db();
    if (defined('PHPBB_31')) {
        $db->sql_connect($dbhost, $dbuser, $dbpasswd, $settings->get_config('dbname'), $dbport, false, false);
    } else {
        $db->sql_connect($dbhost, $dbuser, $dbpasswd, false, $dbport, false, false);
    }
    $db->sql_return_on_error(true);
    return $db;
}
/**
 * Load a schema (and execute)
 *
 * @param string $install_path
 */
function load_schema_30($install_path = '', $install_dbms = false)
{
    global $settings, $db, $table_prefix;
    static $available_dbms = false;
    if ($install_dbms === false) {
        $dbms = $settings->get_config('dbms');
        $install_dbms = $dbms;
    }
    if (!function_exists('get_available_dbms') && !defined('PHPBB_32')) {
        global $phpbb_root_path, $phpEx;
        include $phpbb_root_path . 'includes/functions_install.' . $phpEx;
    }
    if (!$available_dbms) {
        $available_dbms = qi_get_available_dbms($install_dbms);
        if ($install_dbms == 'mysql') {
            if (version_compare($db->mysql_version, '4.1.3', '>=')) {
                $available_dbms[$install_dbms]['SCHEMA'] .= '_41';
            } else {
                $available_dbms[$install_dbms]['SCHEMA'] .= '_40';
            }
        }
    }
    $remove_remarks = $available_dbms[$install_dbms]['COMMENTS'];
    $delimiter = $available_dbms[$install_dbms]['DELIM'];
    $dbms_schema = $install_path . $available_dbms[$install_dbms]['SCHEMA'] . '_schema.sql';
    if (file_exists($dbms_schema)) {
        $sql_query = @file_get_contents($dbms_schema);
        $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
        $remove_remarks($sql_query);
        $sql_query = qi_split_sql_file($sql_query, $delimiter);
        foreach ($sql_query as $sql) {
            $db->sql_query($sql);
        }
        unset($sql_query);
    }
    if (file_exists($install_path . 'schema_data.sql')) {
        $sql_query = file_get_contents($install_path . 'schema_data.sql');
        switch ($install_dbms) {
            case 'mssql':
            case 'mssql_odbc':
                $sql_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $sql_query);
                break;
            case 'postgres':
                $sql_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $sql_query);
                break;
        }
        $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query);
        $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', 'adjust_language_keys_callback', $sql_query);
        remove_remarks($sql_query);
        $sql_query = qi_split_sql_file($sql_query, ';');
        foreach ($sql_query as $sql) {
            $db->sql_query($sql);
        }
        unset($sql_query);
    }
}