Example #1
0
function main($exp, $cmd)
{
    global $SIDU;
    if ($_GET['sql']) {
        $cook = $SIDU['cook'][$SIDU[0]];
        @tm_use_db($cook[1], $cook[2]);
        $mode = "SQL";
        $_GET['sql'] = @stripslashes($_GET['sql']);
    } else {
        $mode = "DB = {$SIDU['1']}" . ($SIDU[2] ? ".{$SIDU['2']}" : "");
    }
    @valid_data($SIDU, $exp, $cmd);
    if ($cmd) {
        @main_cout($SIDU, $exp, $mode);
    } else {
        @main_form($SIDU, $exp, $mode);
    }
}
Example #2
0
function run_sqls()
{
    global $SIDU;
    $conn = $SIDU['conn'][$SIDU[0]];
    $eng = $conn[1];
    $cook = $SIDU['cook'][$SIDU[0]];
    @tm_use_db($cook[1], $cook[2]);
    if ($_GET['sql'] == 'show vars') {
        $_POST['sqlcur'] = $eng == 'pg' ? 'SHOW ALL' : 'SHOW VARIABLES';
    } elseif (@substr($_GET['sql'], 0, 6) == 'FLUSH ') {
        if ($_GET['sql'] == 'FLUSH ALL') {
            $_POST['sqlcur'] = "FLUSH LOGS;\nFLUSH HOSTS;\nFLUSH PRIVILEGES;\nFLUSH TABLES;\nFLUSH STATUS;\nFLUSH DES_KEY_FILE;\nFLUSH QUERY CACHE;\nFLUSH USER_RESOURCES;\nFLUSH TABLES WITH READ LOCK";
        } else {
            $_POST['sqlcur'] = $_GET['sql'];
        }
    } elseif (@substr($_GET['sql'], 0, 9) == 'STATScol:') {
        $_POST['sqlcur'] = "SELECT " . @goodname(@substr($_GET['sql'], 9)) . ",count(*) FROM " . @goodname($cook[4]) . " GROUP BY 1 ORDER BY 2 DESC,1 LIMIT 20";
    } elseif ($_GET['sql']) {
        $_POST['sqlcur'] = $_GET['sql'];
    }
    $arr = @explode(chr(10), @strip($_POST['sqlcur'], 1, 0, 1));
    foreach ($arr as $v) {
        $v = @trim($v);
        if ($v) {
            $arr2[] = $v;
        }
    }
    $txt = @implode(chr(10), $arr2);
    $arr = @explode(";" . chr(10), $txt);
    foreach ($arr as $i => $sql) {
        $time_start = @microtime(true);
        $res = $eng == 'my' ? @mysql_query($sql) : ($eng == 'pg' ? @pg_query($sql) : @sqlite_query($SIDU['dbL'], $sql));
        $time_end = @microtime(true);
        $time = @round(($time_end - $time_start) * 1000);
        $SIDU[5] += $time;
        $err = @sidu_err(1);
        $RES[$i][0] = $sql;
        if ($err) {
            $RES[$i][1] = $err;
            $SIDU[8]++;
        } else {
            $RES[$i][3] = $eng == 'my' ? @mysql_num_rows($res) : ($eng == 'pg' ? @pg_num_rows($res) : @sqlite_num_rows($res));
            if ($eng == 'pg' && !$RES[$i][3]) {
                $RES[$i][2] = @pg_affected_rows($res);
                if (!$RES[$i][2]) {
                    unset($RES[$i][2]);
                }
            }
            //there is no function: sqlite_affected_rows()
            if ($RES[$i][3] === false && $eng == 'my') {
                $RES[$i][2] = @mysql_affected_rows();
            }
            if (!isset($SIDU[6]) && $RES[$i][3] !== false) {
                $SIDU[6] = $i;
                $RES[$i][5] = @get_sql_col($res, $eng);
                $RES[$i][6] = @get_sql_data($res, $eng);
            } elseif ($_POST['sqlmore'] && $RES[$i][3] !== false) {
                $RES[$i][5] = @get_sql_col($res, $eng);
                $RES[$i][6] = @get_sql_data($res, $eng);
            }
            $RES[$i][4] = $time;
        }
        @tm_his_log('S', $sql, $time, $err);
    }
    $SIDU[7] = ++$i;
    $SIDU['RES'] = $RES;
    //reset cookie
    if ($eng == 'my') {
        $db = @mysql_fetch_row(@mysql_query("SELECT database()"));
        if ($db[0] != $cook[1]) {
            $ck = @array($conn[0], $db[0]);
        }
    } elseif ($eng == 'pg') {
        $db[0] = @pg_dbname();
        if ($db[0] != $cook[1]) {
            $ck = @array($conn[0], $db[0]);
        } else {
            //sch
            $sch = pg_fetch_row(pg_query("SHOW search_path"));
            if (@substr($sch[0], 0, 8) == '"$user",') {
                $sch[0] = @substr($sch[0], 8);
            }
            $sch[0] = @str_replace('"', '', $sch[0]);
            if ($sch[0] != $cook[2]) {
                $ck = @array($conn[0], $cook[1], $sch[0]);
            }
        }
    }
    if (isset($ck)) {
        @update_sidu_cook($ck);
    }
}
Example #3
0
function tm($cmd, $tab, $col, $val, $where)
{
    global $SIDU;
    if ($cmd == "SQL") {
        @tm_use_db($col);
        $sql = @trim($tab);
        //sql
        return @tm_his($sql);
    } elseif ($cmd == "SQLS") {
        @tm_use_db($col);
        foreach ($tab as $sql) {
            $res = @tm("SQL", $sql);
        }
        return $res;
    }
    foreach ($val as $k => $v) {
        $val[$k] = @addslashes($v);
    }
    if ($cmd == "insert" || $cmd == "replace") {
        foreach ($col as $i => $v) {
            $CV .= "," . (@strtoupper($val[$i]) === 'NULL' ? "NULL" : ($val[$i] == 'now()' ? $val[$i] : "'{$val[$i]}'"));
        }
        $sql = "{$cmd} INTO {$tab}(" . @implode(",", $col) . ")\nVALUES(" . @substr($CV, 1) . ")";
    } elseif ($cmd == "delete") {
        $sql = "DELETE FROM {$tab}\n{$where}";
    } elseif ($cmd == "update") {
        foreach ($col as $i => $v) {
            $CV .= ",{$col[$i]}=" . (@strtoupper($val[$i]) === 'NULL' ? "NULL" : ($val[$i] == 'now()' ? $val[$i] : "'{$val[$i]}'"));
        }
        $sql = "UPDATE {$tab}\nSET " . @substr($CV, 1) . "\n{$where}";
    }
    if (($cmd == "update" || $cmd == "delete") && $where && $SIDU['page']['hisData']) {
        $sqlL = "SELECT * FROM {$tab} {$where} LIMIT 5";
        if ($SIDU['eng'] == "my") {
            $res = @mysql_query($sqlL);
            while ($row = @mysql_fetch_row($res)) {
                @tm_his_log('D', $row);
            }
        } elseif ($SIDU['eng'] == "pg") {
            $res = @pg_query($sqlL);
            while ($row = @pg_fetch_row($res)) {
                @tm_his_log('D', $row);
            }
        } else {
            $res = @sqlite_query($SIDU['dbL'], $sqlL);
            while ($row = @sqlite_fetch_array($res, SQLITE_NUM)) {
                @tm_his_log('D', $row);
            }
        }
    }
    return @tm_his($sql);
}