function main_cout_data($SIDU, $exp, $res, $tab, $fp) { $col = @get_sql_col($res, $SIDU['eng']); $arr = @get_sql_data($res, $SIDU['eng']); if ($exp['ext'] == "html") { @init_pg_col_align($arr, $col); @main_cout_str("<table style='border:solid 1px #888'>\n<tr class='th'>", $fp); foreach ($col as $v) { @main_cout_str("<td" . ($v[8] == "i" ? " align='right'" : "") . ">{$v['0']}</td>", $fp); } @main_cout_str("</tr>", $fp); } else { $tran = @array(chr(13) => '\\r', chr(10) => '\\n'); $num = count($arr[0]) - 1; if ($exp['ext'] == "sql") { foreach ($col as $k => $v) { $COL[] = @goodname($v[0]); } $head = "\nINSERT INTO " . @goodname($tab) . "(" . @implode(",", $COL) . ") VALUES "; $ttl = count($arr) - 1; $size = $SIDU['eng'] == 'sl' ? 1 : 200; //commit at each 200 lines for select } else { foreach ($col as $k => $v) { $COL[] = $v[0]; } @main_cout_str("\n/*" . @implode(",", $COL) . "*/", $fp); } } if ($exp['ext'] == 'html') { foreach ($arr as $i => $row) { @main_cout_str("\n<tr>", $fp); foreach ($row as $j => $val) { @main_cout_str("<td" . ($col[$j][8] == 'i' ? " align='right'" : "") . (is_null($val) ? " class='n'" : "") . ">" . (is_null($val) ? "NULL" : ($val == '' ? ' ' : @nl2br(@html8($val)))) . "</td>", $fp); } @main_cout_str("</tr>", $fp); } @main_cout_str("\n</table>", $fp); } else { foreach ($arr as $i => $row) { if ($exp['ext'] == 'sql' && $i % $size == 0) { @main_cout_str($head, $fp); } @main_cout_str($exp['ext'] == 'sql' ? "(" : "\n", $fp); foreach ($row as $j => $val) { if (is_null($val)) { @main_cout_str("NULL", $fp); } elseif (is_numeric($val)) { @main_cout_str($val, $fp); } else { $val = @strtr(@addslashes($val), $tran); @main_cout_str("'" . ($exp['zip'] ? $val : @html8($val)) . "'", $fp); } if ($j < $num) { @main_cout_str(",", $fp); } } if ($exp['ext'] == 'sql') { @main_cout_str(")" . ($i == $ttl || $i % $size == $size - 1 ? ";" : ",") . "\n", $fp); } } } }
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); } }