Example #1
0
function dbConnect()
{
    global $db_status;
    if ($db_status == DB_NOT_INITIALIZED) {
        $db_status = dbCreateConnection() && dbSelectDB() && dbConfigure() ? DB_OK : DB_FAIL;
    }
    if ($db_status == DB_FAIL) {
        throw new DBException(mysql_error());
    }
}
Example #2
0
} else {
    $name = get($_POST, 'user');
    if ($name == "") {
        showForm('', 'Enter user name!');
    } else {
        try {
            $db_status = DB_NOT_INITIALIZED;
            $db_config['host'] = get($_POST, 'db_host');
            $db_config['user'] = get($_POST, 'db_user');
            $pwd = get($_POST, 'db_password');
            if ($pwd != '(hidden)') {
                $db_config['password'] = $pwd;
            }
            $db_config['db'] = get($_POST, 'db_db');
            $db_config['prefix'] = get($_POST, 'db_prefix');
            if (!dbCreateConnection()) {
                throw new DBException("Cannot create DB connection.");
            }
            @mysql_query(sprintf("create database %s", mysql_real_escape_string($db_config['db'])));
            dbUpdateTableNames();
            query("drop table if exists {$table['user']}");
            query("create table {$table['user']} (\r\n                     id int auto_increment primary key,\r\n                     name varchar(100),\r\n                     password char(32),\r\n                     role varchar(100),\r\n                     comment longtext,\r\n                     admin_comment longtext,\r\n                     ban_date datetime,\r\n                     banned_by int,\r\n                     ban_reason longtext,\r\n\r\n                     unique index i_name (name)\r\n                 ) default charset='utf8'");
            query("drop table if exists {$table['ip_data']}");
            query("create table {$table['ip_data']} (\r\n                     id int auto_increment primary key,\r\n                     ip varchar(32),\r\n                     admin_comment longtext,\r\n                     ban_date datetime,\r\n                     banned_by int,\r\n                     ban_reason longtext,\r\n\r\n                     unique index i_ip (ip)\r\n                 ) default charset='utf8'");
            query("drop table if exists {$table['source']}");
            query("create table {$table['source']} (\r\n                     id int auto_increment primary key,\r\n                     source longtext,\r\n\r\n                     index i_text (source(256))\r\n                 ) default charset='utf8'");
            query("drop table if exists {$table['translation']}");
            query("create table {$table['translation']} (\r\n                     id int auto_increment primary key,\r\n                     revision int,\r\n                     revert_to int,\r\n                     source_id int,\r\n                     translation longtext,\r\n                     comment longtext,\r\n                     user_id int,\r\n                     user_ip varchar(32),\r\n                     date datetime,\r\n                     \r\n                     index i_source_id (source_id),\r\n                     index i_user_id (user_id),\r\n                     index i_user_ip (user_ip),\r\n                     unique index i_source_id_revision (source_id, revision)\r\n                 ) default charset='utf8'");
            $pwd = get($_POST, 'password');
            $pwd = md5($pwd);
            query("insert into {$table['user']} (id, name, password, role, comment, admin_comment, ban_date, banned_by, ban_reason)\r\n                values(1, ?, ?, 'root', null, null, from_unixtime(0), null, null)", $name, $pwd);