示例#1
0
function CheckSQLParams()
{
    $aDbConf['host'] = $_POST['db_host'];
    $aDbConf['sock'] = $_POST['db_sock'];
    $aDbConf['port'] = $_POST['db_port'];
    $aDbConf['user'] = $_POST['db_user'];
    $aDbConf['passwd'] = $_POST['db_password'];
    $aDbConf['db'] = $_POST['db_name'];
    try {
        $sSocketOrHost = $aDbConf['sock'] ? "unix_socket={$aDbConf['sock']}" : "host={$aDbConf['host']};port={$aDbConf['port']}";
        $vLink = new PDO("mysql:{$sSocketOrHost};dbname={$aDbConf['db']};charset=utf8", $aDbConf['user'], $aDbConf['passwd'], [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""', PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false]);
    } catch (PDOException $e) {
        return printInstallError('MySQL error: ' . $e->getMessage());
    }
    $vLink = null;
}
示例#2
0
function CheckSQLParams()
{
    $aDbConf['host'] = $_POST['db_host'];
    $aDbConf['sock'] = $_POST['db_sock'];
    $aDbConf['port'] = $_POST['db_port'];
    $aDbConf['user'] = $_POST['db_user'];
    $aDbConf['passwd'] = $_POST['db_password'];
    $aDbConf['db'] = $_POST['db_name'];
    $aDbConf['host'] .= ($aDbConf['port'] ? ":{$aDbConf['port']}" : '') . ($aDbConf['sock'] ? ":{$aDbConf['sock']}" : '');
    $vLink = @mysql_connect($aDbConf['host'], $aDbConf['user'], $aDbConf['passwd']);
    if (!$vLink) {
        return printInstallError('MySQL error: ' . mysql_error());
    }
    if (!mysql_select_db($aDbConf['db'], $vLink)) {
        return printInstallError('MySQL error: ' . mysql_error($vLink));
    }
    mysql_close($vLink);
}
function RunSQL($sAdminName, $sAdminPassword)
{
    $db['host'] = $_POST['db_host'];
    $db['sock'] = $_POST['db_sock'];
    $db['port'] = $_POST['db_port'];
    $db['user'] = $_POST['db_user'];
    $db['passwd'] = $_POST['db_password'];
    $db['db'] = $_POST['db_name'];
    $db['host'] .= ($db['port'] ? ":{$db['port']}" : '') . ($db['sock'] ? ":{$db['sock']}" : '');
    $pass = true;
    $errorMes = '';
    $filename = $_POST['sql_file'];
    $link = @mysql_connect($db['host'], $db['user'], $db['passwd']);
    if (!$link) {
        return printInstallError(mysql_error());
    }
    //return ("<font color=red>Could not connect to MySQL server: " . mysql_error()."</font>");
    if (!mysql_select_db($db['db'], $link)) {
        return printInstallError($db['db'] . ': ' . mysql_error());
    }
    //return ("<font color=red>Could not select database '{$db['db']}': " . mysql_error()."</font>");
    if (!($f = fopen($filename, "r"))) {
        return printInstallError('Could not open file with sql instructions:' . $filename);
    }
    //return ("<font color=red>Could not open file with sql instructions: $filename </font>");
    //Begin SQL script executing
    $s_sql = "";
    while ($s = fgets($f, 10240)) {
        $s = trim($s);
        //Utf with BOM only
        if (!strlen($s)) {
            continue;
        }
        if (mb_substr($s, 0, 1) == '#') {
            continue;
        }
        //pass comments
        if (mb_substr($s, 0, 2) == '--') {
            continue;
        }
        if (substr($s, 0, 5) == "--") {
            continue;
        }
        $s_sql .= $s;
        if (mb_substr($s, -1) != ';') {
            continue;
        }
        $res = mysql_query($s_sql, $link);
        if (!$res) {
            $errorMes .= 'Error while executing: ' . $s_sql . '<br />' . mysql_error() . '<hr />';
        }
        $s_sql = "";
    }
    mysql_query("UPDATE `Admins` SET `Name`='{$sAdminName}', `Password`=md5( '{$sAdminPassword}' ) WHERE `Name`='admin'", $link);
    if (!$res) {
        $errorMes .= 'Error while executing: ' . $s_sql . '<br />' . mysql_error() . '<hr />';
    }
    fclose($f);
    $enable_gd_value = extension_loaded('gd') ? 'on' : '';
    if (!mysql_query("UPDATE `GlParams` SET `VALUE`='{$enable_gd_value}' WHERE `Name`='enable_gd'", $link)) {
        $ret .= "<font color=red><i><b>Error</b>:</i> " . mysql_error() . "</font><hr>";
    }
    mysql_close($link);
    $errorMes .= $ret;
    if (strlen($errorMes)) {
        return printInstallError($errorMes);
    } else {
        return 'done';
    }
    //    return $ret."Truncating tables finished.<br>";
}