' . "\n";
echo '' . htmlspecialchars($stripped_sql_query) . ' ?
' . "\n";
?>
left frame should be reloaded
if ((!isset($reload) || $reload == 0)
&& eregi('^CREATE TABLE[[:space:]]+(.*)', $sql_query)) {
$reload = 1;
}
// Gets the number of rows per page
if (!isset($session_max_rows)) {
$session_max_rows = $cfg['MaxRows'];
} else if ($session_max_rows != 'all') {
$cfg['MaxRows'] = $session_max_rows;
}
// Defines the display mode (horizontal/vertical) and header "frequency"
if (empty($disp_direction)) {
$disp_direction = $cfg['DefaultDisplay'];
}
if (empty($repeat_cells)) {
$repeat_cells = $cfg['RepeatCells'];
}
$is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = FALSE;
if ($is_select) { // see line 76
$is_count = (eregi('^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)', $sql_query));
$is_export = (eregi('[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+', $sql_query));
$is_analyse = (eregi('[[:space:]]+PROCEDURE[[:space:]]+ANALYSE\(', $sql_query));
} else if (eregi('^EXPLAIN[[:space:]]+', $sql_query)) {
$is_explain = TRUE;
} else if (eregi('^DELETE[[:space:]]+', $sql_query)) {
$is_delete = TRUE;
$is_affected = TRUE;
} else if (eregi('^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+', $sql_query)) {
$is_insert = TRUE;
$is_affected = TRUE;
} else if (eregi('^UPDATE[[:space:]]+', $sql_query)) {
$is_affected = TRUE;
} else if (eregi('^SHOW[[:space:]]+', $sql_query)) {
$is_show = TRUE;
} else if (eregi('^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+', $sql_query)) {
$is_maint = TRUE;
}
// Do append a "LIMIT" clause?
if (isset($pos)
&& (!$cfg['ShowAll'] || $session_max_rows != 'all')
&& $is_select
&& !($is_count || $is_export)
&& eregi('[[:space:]]FROM[[:space:]]', $sql_query)
&& !eregi('[[:space:]]LIMIT[[:space:]0-9,]+$', $sql_query)) {
$sql_limit_to_append = " LIMIT $pos, ".$cfg['MaxRows'];
if (eregi('(.*)([[:space:]](PROCEDURE[[:space:]](.*)|FOR[[:space:]]+UPDATE|LOCK[[:space:]]+IN[[:space:]]+SHARE[[:space:]]+MODE))$', $sql_query, $regs)) {
$full_sql_query = $regs[1] . $sql_limit_to_append . $regs[2];
} else {
$full_sql_query = $sql_query . $sql_limit_to_append;
}
} else {
$full_sql_query = $sql_query;
} // end if...else
mysql_select_db($db);
// If the query is a DELETE query with no WHERE clause, get the number of
// rows that will be deleted (mysql_affected_rows will always return 0 in
// this case)
if ($is_delete
&& eregi('^DELETE([[:space:]].+)?([[:space:]]FROM[[:space:]](.+))$', $sql_query, $parts)
&& !eregi('[[:space:]]WHERE[[:space:]]', $parts[3])) {
$cnt_all_result = @mysql_query('SELECT COUNT(*) as count' . $parts[2]);
if ($cnt_all_result) {
$num_rows = mysql_result($cnt_all_result, 0, 'count');
mysql_free_result($cnt_all_result);
} else {
$num_rows = 0;
}
}
// Executes the query
$result = @mysql_query($full_sql_query);
// Displays an error message if required and stop parsing the script
if (mysql_error()) {
$error = mysql_error();
include('./header.inc.php3');
$full_err_url = (ereg('^(db_details|tbl_properties)', $err_url))
? $err_url . '&show_query=y&sql_query=' . urlencode($sql_query)
: $err_url;
PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
}
// tmpfile remove after convert encoding appended by Y.Kawada
if (function_exists('PMA_kanji_file_conv')
&& (isset($textfile) && file_exists($textfile))) {
unlink($textfile);
}
// Gets the number of rows affected/returned
if (!$is_affected) {
$num_rows = ($result) ? @mysql_num_rows($result) : 0;
} else if (!isset($num_rows)) {
$num_rows = @mysql_affected_rows();
}
// Counts the total number of rows for the same 'SELECT' query without the
// 'LIMIT' clause that may have been programatically added
if (empty($sql_limit_to_append)) {
$unlim_num_rows = $num_rows;
}
else if ($is_select) {
// reads only the from-part of the query...
$sp='[[:space:]]';
$array = split(
$sp . 'from' . $sp .'|' . $sp . 'FROM' .$sp .
'|' . $sp .'order' . $sp . '|' . $sp . 'ORDER' . $sp .
'|' . $sp .'having' . $sp . '|' . $sp . 'HAVING' . $sp .
'|' . $sp .'limit' . $sp . '|' . $sp . 'LIMIT' . $sp .
'|' . $sp .'group' . $sp . 'by'. $sp .
'|' . $sp . 'GROUP' . $sp . 'BY' . $sp, $sql_query);
if (!empty($array[1])) {
// ... and makes a count(*) to count the entries
$count_query = 'SELECT COUNT(*) AS count FROM ' . $array[1];
$cnt_all_result = mysql_query($count_query);
if ($cnt_all_result) {
$unlim_num_rows = mysql_result($cnt_all_result, 0, 'count');
mysql_free_result($cnt_all_result);
}
} else {
$unlim_num_rows = 0;
}
} // end rows total count
// No rows returned -> move back to the calling page
if ($num_rows < 1 || $is_affected) {
if ($is_delete) {
$message = $strDeletedRows . ' ' . $num_rows;
} else if ($is_insert) {
$message = $strInsertedRows . ' ' . $num_rows;
} else if ($is_affected) {
$message = $strAffectedRows . ' ' . $num_rows;
} else if (!empty($zero_rows)) {
$message = $zero_rows;
} else {
$message = $strEmptyResultSet;
}
if ($is_gotofile) {
$goto = ereg_replace('\.\.*', '.', $goto);
// Checks for a valid target script
if (isset($table) && $table == '') {
unset($table);
}
if (isset($db) && $db == '') {
unset($db);
}
$is_db = $is_table = FALSE;
if (strpos(' ' . $goto, 'tbl_properties') == 1) {
if (!isset($table)) {
$goto = 'db_details.php3';
} else {
$is_table = @mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'');
if (!($is_table && @mysql_numrows($is_table))) {
$goto = 'db_details.php3';
unset($table);
}
} // end if... else...
}
if (strpos(' ' . $goto, 'db_details.php3') == 1) {
if (isset($table)) {
unset($table);
}
if (!isset($db)) {
$goto = 'main.php3';
} else {
$is_db = @mysql_select_db($db);
if (!$is_db) {
$goto = 'main.php3';
unset($db);
}
} // end if... else...
}
// Loads to target script
if (strpos(' ' . $goto, 'db_details') == 1
|| strpos(' ' . $goto, 'tbl_properties') == 1) {
$js_to_run = 'functions.js';
}
if ($goto != 'main.php3') {
include('./header.inc.php3');
}
include('./' . $goto);
} // end if file_exist
else {
header('Location: ' . $cfg['PmaAbsoluteUri'] . str_replace('&', '&', $goto) . '&message=' . urlencode($message));
} // end else
exit();
} // end no rows returned
// At least one row is returned -> displays a table with results
else {
// Displays the headers
if (isset($show_query)) {
unset($show_query);
}
$js_to_run = 'functions.js';
include('./header.inc.php3');
include('./libraries/bookmark.lib.php3');
// Gets the list of fields properties
while ($field = mysql_fetch_field($result)) {
$fields_meta[] = $field;
}
$fields_cnt = count($fields_meta);
// Displays the results in a table
include('./libraries/display_tbl.lib.php3');
if (empty($disp_mode)) {
// see the "PMA_setDisplayMode()" function in
// libraries/display_tbl.lib.php3
$disp_mode = 'urdr11110';
}
PMA_displayTable($result, $disp_mode);
mysql_free_result($result);
// Displays "Insert a new row" link if required
if ($disp_mode[6] == '1') {
$lnk_goto = 'sql.php3'
. '?lang=' . $lang
. '&server=' . $server
. '&db=' . urlencode($db)
. '&table=' . urlencode($table)
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&sql_query=' . urlencode($sql_query);
$url_query = 'lang=' . $lang
. '&server=' . $server
. '&db=' . urlencode($db)
. '&table=' . urlencode($table)
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&sql_query=' . urlencode($sql_query)
. '&goto=' . urlencode($lnk_goto);
echo "\n\n";
echo '' . "\n";
echo '' . "\n";
echo ' ' . $strInsertNewRow . '' . "\n";
echo '
' . "\n";
} // end insert new row
// Bookmark Support if required
if ($disp_mode[7] == '1'
&& ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table'] && empty($id_bookmark))
&& !empty($sql_query)) {
echo "\n";
$goto = 'sql.php3'
. '?lang=' . $lang
. '&server=' . $server
. '&db=' . urlencode($db)
. '&table=' . urlencode($table)
. '&pos=' . $pos
. '&session_max_rows=' . $session_max_rows
. '&disp_direction=' . $disp_direction
. '&repeat_cells=' . $repeat_cells
. '&sql_query=' . urlencode($sql_query)
. '&id_bookmark=1';
?>