コード例 #1
0
ファイル: roster.php プロジェクト: Sajaki/wowroster_dev
 /**
  * Load the DBAL
  */
 function load_dbal()
 {
     global $db_config;
     switch ($db_config['dbtype']) {
         case 'mysql':
             include_once ROSTER_LIB . 'dbal' . DIR_SEP . 'mysql.php';
             break;
         case 'mysqli':
             include_once ROSTER_LIB . 'dbal' . DIR_SEP . 'mysqli.php';
             break;
         case 'pdo':
             include_once ROSTER_LIB . 'dbal' . DIR_SEP . 'pdo.php';
             break;
         case 'external':
             include_once ROSTER_LIB . 'dbal' . DIR_SEP . 'external.php';
             break;
         default:
             include_once ROSTER_LIB . 'dbal' . DIR_SEP . 'mysql.php';
             break;
     }
     $this->db = new roster_db($db_config['host'], $db_config['database'], $db_config['username'], $db_config['password'], $db_config['table_prefix']);
     $this->db->log_level();
     if (!$this->db->link_id) {
         die(__FILE__ . ': line[' . __LINE__ . ']<br />Could not connect to database "' . $db_config['database'] . '"<br />MySQL 1 said:<br />' . $this->db->connect_error());
     }
 }
コード例 #2
0
ファイル: install.php プロジェクト: Sajaki/wowroster_dev
function process_step3()
{
    global $DEFAULTS, $DBALS, $LOCALES, $REQUIRE;
    $tpl = new Template_Wrap();
    $tpl->set_handle('body', 'install_step3.html');
    /**
     * Get our posted data
     */
    $db_config['dbtype'] = post_or_db('dbtype');
    $db_config['host'] = post_or_db('dbhost');
    $db_config['database'] = post_or_db('dbname');
    $db_config['username'] = post_or_db('dbuser');
    $db_config['password'] = post_or_db('dbpass');
    $db_config['table_prefix'] = post_or_db('table_prefix', $DEFAULTS);
    $default_locale = post_or_db('default_lang', $DEFAULTS);
    $server_name = post_or_db('server_name');
    $create['username'] = post_or_db('dbuser_c');
    $create['password'] = post_or_db('dbpass_c');
    define('ROSTER_DB_DIR', ROSTER_LIB . 'dbal' . DIR_SEP);
    $dbal_file = ROSTER_DB_DIR . $db_config['dbtype'] . '.php';
    if (!file_exists($dbal_file)) {
        $tpl->message_die('Unable to find the database abstraction layer for <strong>' . $db_config['dbtype'] . '</strong>, check to make sure ' . $dbal_file . ' exists.');
    }
    /**
     * Database population
     */
    include_once $dbal_file;
    // Hey, looks like we are making the database, YAY!
    if ($create['username'] != '' && $create['password'] != '') {
        include_once $dbal_file;
        $db = new roster_db($db_config['host'], '', $create['username'], $create['password']);
        $db->query("CREATE DATABASE IF NOT EXISTS `" . $db_config['database'] . "`;");
        unset($db, $create);
    }
    // Try to connect
    $db = new roster_db($db_config['host'], $db_config['database'], $db_config['username'], $db_config['password'], $db_config['table_prefix']);
    $db->log_level();
    $db->error_die();
    // Check to make sure a connection was made
    if (!is_resource($db->link_id)) {
        // Attempt to
        $tpl->message_die('Failed to connect to database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->connect_error() . '<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>');
    }
    $db_structure_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_structure.sql';
    $db_data_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_data.sql';
    $remove_remarks_function = $DBALS[$db_config['dbtype']]['comments'];
    // I require MySQL version 4.1.0 minimum.
    $server_version = $db->server_info();
    $client_version = $db->client_info();
    if (isset($server_version) && isset($client_version)) {
        $tpl->message_append('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br />
			<strong>You are running:</strong>
			<ul>
				<li><strong>Your server version: ' . $server_version . '</strong></li>
				<li><strong>Your client version: ' . $client_version . '</strong></li>
			</ul>
			Your server meets the MySQL requirements for WoWRoster.');
        if (version_compare($server_version, $REQUIRE['mysql_version'], '<')) {
            $tpl->message_die('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br />
				<strong>You are running:</strong>
				<ul>
					<li><strong>Your server version: ' . $server_version . '</strong></li>
					<li><strong>Your client version: ' . $client_version . '</strong></li>
				</ul>
				We are sorry, your MySQL server version is not high enough to install WoWRoster, please upgrade MySQL.');
        }
    } else {
        $tpl->message_die('Failed to get version information for database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->connect_error() . '<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>');
    }
    // Parse structure file and create database tables
    $sql = @fread(@fopen($db_structure_file, 'r'), @filesize($db_structure_file));
    $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql);
    $sql = $remove_remarks_function($sql);
    $sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']);
    $sql_count = count($sql);
    $i = 0;
    while ($i < $sql_count) {
        if (isset($sql[$i]) && $sql[$i] != '') {
            if (!$db->query($sql[$i])) {
                $tpl->message_die('Error in SQL query<br />' . $sql[$i] . '<br />' . 'Error: ' . $db->error() . '<br />' . '<a href="index.php">Restart Installation</a>');
            }
        }
        $i++;
    }
    unset($sql);
    // Parse the data file and populate the database tables
    $sql = @fread(@fopen($db_data_file, 'r'), @filesize($db_data_file));
    $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql);
    $sql = $remove_remarks_function($sql);
    $sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']);
    $sql_count = count($sql);
    $i = 0;
    while ($i < $sql_count) {
        if (isset($sql[$i]) && $sql[$i] != '') {
            if (!$db->query($sql[$i])) {
                $tpl->message_die('Error in SQL query<br />' . $sql[$i] . '<br />' . 'Error: ' . $db->error() . '<br />' . '<a href="index.php">Restart Installation</a>');
            }
        }
        $i++;
    }
    unset($sql);
    /**
     * Update some config settings
     */
    $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '{$default_locale}' WHERE `config_name` = 'locale';");
    $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '" . ROSTER_VERSION . "' WHERE `config_name` = 'version';");
    $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '{$server_name}' WHERE `config_name` = 'website_address';");
    /**
     * Write the config file
     */
    $config_file = "<?php\n";
    $config_file .= "/**\n * AUTO-GENERATED CONF FILE\n * DO NOT EDIT !!!\n */\n\n";
    $config_file .= "\$db_config['host']         = " . var_export($db_config['host'], true) . ";\n";
    $config_file .= "\$db_config['username']     = "******";\n";
    $config_file .= "\$db_config['password']     = "******";\n";
    $config_file .= "\$db_config['database']     = " . var_export($db_config['database'], true) . ";\n";
    $config_file .= "\$db_config['table_prefix'] = " . var_export($db_config['table_prefix'], true) . ";\n";
    $config_file .= "\$db_config['dbtype']       = " . var_export($db_config['dbtype'], true) . ";\n";
    // Set our permissions to execute-only
    @umask(0111);
    if (!($fp = @fopen('conf.php', 'w'))) {
        $error_message = 'The <strong>conf.php</strong> file couldn\'t be opened for writing.  Paste the following in to conf.php and save the file to continue:<br /><pre>' . htmlspecialchars($config_file) . '</pre>';
        $tpl->error_append($error_message);
    } else {
        @fputs($fp, $config_file);
        @fclose($fp);
        $tpl->message_append('Your configuration file has been written with the initial values<br />But installation will not be complete until you create an administrator account in this step');
    }
    /**
     * Output the page
     */
    $tpl->sql_output($db);
    $tpl->page_header();
    $tpl->page_tail();
}