Esempio n. 1
0
function safe_w_SQL($SQL, $use = false, $acc_error = array(0))
{
    global $WRIT_CON, $ERROR_REPORT, $CFG;
    if ($ERROR_REPORT and $CFG->TRACE_QUERRIES) {
        $a = debug_backtrace();
        $GLOBALS['safe_SQL']['w_querries'][] = $a[0];
    }
    if (!$WRIT_CON) {
        $WRIT_CON = safe_w_con();
    }
    if ($use) {
        $a = mysqli_query($WRIT_CON, $SQL, MYSQLI_USE_RESULT) or in_array(mysqli_errno($WRIT_CON), $acc_error) or safe_error('Errore ' . mysqli_errno($WRIT_CON) . ': ' . mysqli_error($WRIT_CON));
    } else {
        $a = mysqli_query($WRIT_CON, $SQL) or in_array(mysqli_errno($WRIT_CON), $acc_error) or safe_error('Errore ' . mysqli_errno($WRIT_CON) . ': ' . mysqli_error($WRIT_CON));
    }
    return $a;
}
Esempio n. 2
0
function check_write_DB($tipo, $W_HOST, $W_USER, $W_PASS)
{
    global $CFG, $WRIT_CON;
    $a = safe_w_con(true);
    // ritorna con l'errore di collegamento
    $testi = $tipo == 'W' ? 'Write' : 'Read';
    if ($a == 'CONNECTION_FAILED' or is_array($a)) {
        // se è stata fornita la password di root, proviamo a collegarci come root
        if (isset($_POST[$tipo . '_ROOT'])) {
            $CFG->W_USER = '******';
            $CFG->W_PASS = stripslashes(trim($_POST[$tipo . '_ROOT']));
            $a = safe_w_con(true);
            if ($a == 'CONNECTION_FAILED') {
                $_SESSION['INSTALL']['CFG']['ERROR'] = get_text($testi . ' connection failed', 'Install');
                cd_redirect('?step=2');
            }
            if (is_array($a) and $a[1] == 'NO_DATABASE') {
                // beh... bisogna creare il DB :)
                $WRIT_CON = $a[0];
                safe_w_sql("CREATE DATABASE `{$CFG->DB_NAME}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;");
                // poi garantire l'accesso all'utente
                safe_w_sql("grant all privileges on `" . $CFG->DB_NAME . "`.* to '{$W_USER}'@'{$W_HOST}' identified by '" . addslashes($W_PASS) . "';");
                // infine inserire nel DB la struttura di base
                // ma prima rimuovere la connessione per forzarne una nuova
                $WRIT_CON = null;
                $CFG->W_USER = $W_USER;
                $CFG->W_PASS = $W_PASS;
                install_blank_db();
                // e ritorna falso (creato ex novo)
                return false;
            }
        } elseif (is_array($a) and $a[1] == 'NO_DATABASE') {
            $_SESSION['INSTALL']['CFG']['ERROR'] = get_text($testi . ' Database not present', 'Install');
            cd_redirect('?step=2');
        }
        // in ogni caso ritorna sulla pagina via un get per eliminare i POST
        $_SESSION['INSTALL']['CFG']['ERROR'] = get_text($testi . ' connection failed', 'Install');
        cd_redirect('?step=2');
    }
    // se la connessione è stata stabilita senza problemi bisogna fare il dump
    // quindi ritorna true!
    return true;
}