added known limitation
[phpmyadmin/crack.git] / sql.php
bloba3006e99201c1abc0923db5ddcf8618e903723bf
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @todo we must handle the case if sql.php is called directly with a query
5 * what returns 0 rows - to prevent cyclic redirects or includes
6 * @version $Id$
7 */
9 /**
10 * Gets some core libraries
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
14 require_once './libraries/tbl_indexes.lib.php';
15 require_once './libraries/check_user_privileges.lib.php';
16 require_once './libraries/bookmark.lib.php';
18 /**
19 * Could be coming from a subform ("T" column expander)
21 if (isset($_REQUEST['dontlimitchars'])) {
22 $dontlimitchars = $_REQUEST['dontlimitchars'];
25 /**
26 * Defines the url to return to in case of error in a sql statement
28 // Security checkings
29 if (!empty($goto)) {
30 $is_gotofile = preg_replace('@^([^?]+).*$@s', '\\1', $goto);
31 if (!@file_exists('./' . $is_gotofile)) {
32 unset($goto);
33 } else {
34 $is_gotofile = ($is_gotofile == $goto);
36 } // end if (security checkings)
38 if (empty($goto)) {
39 $goto = (! strlen($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
40 $is_gotofile = true;
41 } // end if
42 if (!isset($err_url)) {
43 $err_url = (!empty($back) ? $back : $goto)
44 . '?' . PMA_generate_common_url($db)
45 . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table)) ? '&amp;table=' . urlencode($table) : '');
46 } // end if
48 // Coming from a bookmark dialog
49 if (isset($fields['query'])) {
50 $sql_query = $fields['query'];
53 // This one is just to fill $db
54 if (isset($fields['dbase'])) {
55 $db = $fields['dbase'];
58 // Default to browse if no query set an we have table
59 // (needed for browsing from DefaultTabTable)
60 if (empty($sql_query) && strlen($table) && strlen($db)) {
61 require_once './libraries/bookmark.lib.php';
62 $book_sql_query = PMA_queryBookmarks($db,
63 $GLOBALS['cfg']['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'',
64 'label');
66 if (! empty($book_sql_query)) {
67 $sql_query = $book_sql_query;
68 } else {
69 $sql_query = 'SELECT * FROM ' . PMA_backquote($table);
71 unset($book_sql_query);
73 // set $goto to what will be displayed if query returns 0 rows
74 $goto = 'tbl_structure.php';
75 } else {
76 // Now we can check the parameters
77 PMA_checkParameters(array('sql_query'));
80 // instead of doing the test twice
81 $is_drop_database = preg_match('/DROP[[:space:]]+(DATABASE|SCHEMA)[[:space:]]+/i',
82 $sql_query);
84 /**
85 * Check rights in case of DROP DATABASE
87 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
88 * but since a malicious user may pass this variable by url/form, we don't take
89 * into account this case.
91 if (!defined('PMA_CHK_DROP')
92 && !$cfg['AllowUserDropDatabase']
93 && $is_drop_database
94 && !$is_superuser) {
95 require_once './libraries/header.inc.php';
96 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
97 } // end if
101 * Need to find the real end of rows?
104 if (isset($find_real_end) && $find_real_end) {
105 $unlim_num_rows = PMA_Table::countRecords($db, $table, true, true);
106 $pos = @((ceil($unlim_num_rows / $session_max_rows) - 1) * $session_max_rows);
109 * Avoids undefined variables
111 elseif (!isset($pos)) {
112 $pos = 0;
113 } else {
114 /* We need this to be a integer */
115 $pos = (int)$pos;
119 * Bookmark add
121 if (isset($store_bkm)) {
122 PMA_addBookmarks($fields, $cfg['Bookmark'], (isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false));
123 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . $goto);
124 } // end if
128 * Gets the true sql query
130 // $sql_query has been urlencoded in the confirmation form for drop/delete
131 // queries or in the navigation bar for browsing among records
132 if (isset($btnDrop) || isset($navig)) {
133 $sql_query = urldecode($sql_query);
137 * Parse and analyze the query
139 require_once './libraries/parse_analyze.lib.php';
142 * Sets or modifies the $goto variable if required
144 if ($goto == 'sql.php') {
145 $is_gotofile = false;
146 $goto = 'sql.php?'
147 . PMA_generate_common_url($db, $table)
148 . '&amp;pos=' . $pos
149 . '&amp;sql_query=' . urlencode($sql_query);
150 } // end if
154 * Go back to further page if table should not be dropped
156 if (isset($btnDrop) && $btnDrop == $strNo) {
157 if (!empty($back)) {
158 $goto = $back;
160 if ($is_gotofile) {
161 if (strpos(' ' . $goto, 'db_') == 1 && strlen($table)) {
162 $table = '';
164 $active_page = $goto;
165 require './' . PMA_securePath($goto);
166 } else {
167 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
169 exit();
170 } // end if
174 * Displays the confirm page if required
176 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
177 * with js) because possible security issue is not so important here: at most,
178 * the confirm message isn't displayed.
180 * Also bypassed if only showing php code.or validating a SQL query
182 if (! $cfg['Confirm'] || isset($_REQUEST['is_js_confirmed']) || isset($btnDrop)
183 // if we are coming from a "Create PHP code" or a "Without PHP Code"
184 // dialog, we won't execute the query anyway, so don't confirm
185 //|| !empty($GLOBALS['show_as_php'])
186 || isset($GLOBALS['show_as_php'])
187 || !empty($GLOBALS['validatequery'])) {
188 $do_confirm = false;
189 } else {
190 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
193 if ($do_confirm) {
194 $stripped_sql_query = $sql_query;
195 require_once './libraries/header.inc.php';
196 if ($is_drop_database) {
197 echo '<h1 class="warning">' . $strDropDatabaseStrongWarning . '</h1>';
199 echo '<form action="sql.php" method="post">' . "\n"
200 .PMA_generate_common_hidden_inputs($db, $table);
202 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
203 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? PMA_sanitize($zero_rows) : ''; ?>" />
204 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
205 <input type="hidden" name="back" value="<?php echo isset($back) ? PMA_sanitize($back) : ''; ?>" />
206 <input type="hidden" name="reload" value="<?php echo isset($reload) ? PMA_sanitize($reload) : 0; ?>" />
207 <input type="hidden" name="purge" value="<?php echo isset($purge) ? PMA_sanitize($purge) : ''; ?>" />
208 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? PMA_sanitize($cpurge) : ''; ?>" />
209 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? PMA_sanitize($purgekey) : ''; ?>" />
210 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? PMA_sanitize($show_query) : ''; ?>" />
211 <?php
212 echo '<fieldset class="confirmation">' . "\n"
213 .' <legend>' . $strDoYouReally . '</legend>'
214 .' <tt>' . htmlspecialchars($stripped_sql_query) . '</tt>' . "\n"
215 .'</fieldset>' . "\n"
216 .'<fieldset class="tblFooters">' . "\n";
218 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" id="buttonYes" />
219 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" id="buttonNo" />
220 <?php
221 echo '</fieldset>' . "\n"
222 . '</form>' . "\n";
225 * Displays the footer and exit
227 require_once './libraries/footer.inc.php';
228 } // end if $do_confirm
231 // Defines some variables
232 // A table has to be created or renamed -> left frame should be reloaded
234 * @todo use the parser/analyzer
237 if (empty($reload)
238 && preg_match('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
239 $reload = 1;
241 // Gets the number of rows per page
242 if (empty($session_max_rows)) {
243 $session_max_rows = $cfg['MaxRows'];
244 } elseif ($session_max_rows != 'all') {
245 $cfg['MaxRows'] = $session_max_rows;
247 // Defines the display mode (horizontal/vertical) and header "frequency"
248 if (empty($disp_direction)) {
249 $disp_direction = $cfg['DefaultDisplay'];
251 if (empty($repeat_cells)) {
252 $repeat_cells = $cfg['RepeatCells'];
255 // SK -- Patch: $is_group added for use in calculation of total number of
256 // rows.
257 // $is_count is changed for more correct "LIMIT" clause
258 // appending in queries like
259 // "SELECT COUNT(...) FROM ... GROUP BY ..."
262 * @todo detect all this with the parser, to avoid problems finding
263 * those strings in comments or backquoted identifiers
266 $is_explain = $is_count = $is_export = $is_delete = $is_insert = $is_affected = $is_show = $is_maint = $is_analyse = $is_group = $is_func = $is_replace = false;
267 if ($is_select) { // see line 141
268 $is_group = preg_match('@(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+@i', $sql_query);
269 $is_func = !$is_group && (preg_match('@[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(@i', $sql_query));
270 $is_count = !$is_group && (preg_match('@^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)@i', $sql_query));
271 $is_export = (preg_match('@[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+@i', $sql_query));
272 $is_analyse = (preg_match('@[[:space:]]+PROCEDURE[[:space:]]+ANALYSE@i', $sql_query));
273 } elseif (preg_match('@^EXPLAIN[[:space:]]+@i', $sql_query)) {
274 $is_explain = true;
275 } elseif (preg_match('@^DELETE[[:space:]]+@i', $sql_query)) {
276 $is_delete = true;
277 $is_affected = true;
278 } elseif (preg_match('@^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+@i', $sql_query)) {
279 $is_insert = true;
280 $is_affected = true;
281 if (preg_match('@^(REPLACE)[[:space:]]+@i', $sql_query)) {
282 $is_replace = true;
284 } elseif (preg_match('@^UPDATE[[:space:]]+@i', $sql_query)) {
285 $is_affected = true;
286 } elseif (preg_match('@^SHOW[[:space:]]+@i', $sql_query)) {
287 $is_show = true;
288 } elseif (preg_match('@^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+@i', $sql_query)) {
289 $is_maint = true;
292 // Do append a "LIMIT" clause?
293 if (isset($pos)
294 && (!$cfg['ShowAll'] || $session_max_rows != 'all')
295 && !($is_count || $is_export || $is_func || $is_analyse)
296 && isset($analyzed_sql[0]['queryflags']['select_from'])
297 && !isset($analyzed_sql[0]['queryflags']['offset'])
298 && !preg_match('@[[:space:]]LIMIT[[:space:]0-9,-]+(;)?$@i', $sql_query)) {
299 $sql_limit_to_append = " LIMIT $pos, ".$cfg['MaxRows'] . " ";
301 $full_sql_query = $analyzed_sql[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_sql[0]['section_after_limit'];
303 * @todo pretty printing of this modified query
305 if (isset($display_query)) {
306 // if the analysis of the original query revealed that we found
307 // a section_after_limit, we now have to analyze $display_query
308 // to display it correctly
310 if (!empty($analyzed_sql[0]['section_after_limit']) && trim($analyzed_sql[0]['section_after_limit']) != ';') {
311 $analyzed_display_query = PMA_SQP_analyze(PMA_SQP_parse($display_query));
312 $display_query = $analyzed_display_query[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_display_query[0]['section_after_limit'];
316 } else {
317 $full_sql_query = $sql_query;
318 } // end if...else
320 if (strlen($db)) {
321 PMA_DBI_select_db($db);
324 // If the query is a DELETE query with no WHERE clause, get the number of
325 // rows that will be deleted (mysql_affected_rows will always return 0 in
326 // this case)
327 // Note: testing shows that this no longer applies since MySQL 4.0.x
329 if (PMA_MYSQL_INT_VERSION < 40000) {
330 if ($is_delete
331 && preg_match('@^DELETE([[:space:]].+)?(FROM[[:space:]](.+))$@i', $sql_query, $parts)
332 && !preg_match('@[[:space:]]WHERE[[:space:]]@i', $parts[3])) {
333 $cnt_all_result = @PMA_DBI_try_query('SELECT COUNT(*) as count ' . $parts[2]);
334 if ($cnt_all_result) {
335 list($num_rows) = PMA_DBI_fetch_row($cnt_all_result);
336 PMA_DBI_free_result($cnt_all_result);
337 } else {
338 $num_rows = 0;
343 // E x e c u t e t h e q u e r y
345 // Only if we didn't ask to see the php code (mikebeck)
346 if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
347 unset($result);
348 $num_rows = 0;
349 } else {
350 // garvin: Measure query time.
351 // TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
352 $querytime_before = array_sum(explode(' ', microtime()));
354 $result = @PMA_DBI_try_query($full_sql_query, null, PMA_DBI_QUERY_STORE);
356 $querytime_after = array_sum(explode(' ', microtime()));
358 $GLOBALS['querytime'] = $querytime_after - $querytime_before;
360 // Displays an error message if required and stop parsing the script
361 if ($error = PMA_DBI_getError()) {
362 require_once './libraries/header.inc.php';
363 $full_err_url = (preg_match('@^(db|tbl)_@', $err_url))
364 ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
365 : $err_url;
366 PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
368 unset($error);
370 // Gets the number of rows affected/returned
371 // (This must be done immediately after the query because
372 // mysql_affected_rows() reports about the last query done)
374 if (!$is_affected) {
375 $num_rows = ($result) ? @PMA_DBI_num_rows($result) : 0;
376 } elseif (!isset($num_rows)) {
377 $num_rows = @PMA_DBI_affected_rows();
380 // Checks if the current database has changed
381 // This could happen if the user sends a query like "USE `database`;"
382 $res = PMA_DBI_query('SELECT DATABASE() AS \'db\';');
383 $row = PMA_DBI_fetch_row($res);
384 if (strlen($db) && is_array($row) && isset($row[0]) && (strcasecmp($db, $row[0]) != 0)) {
385 $db = $row[0];
386 $reload = 1;
388 @PMA_DBI_free_result($res);
389 unset($res, $row);
391 // tmpfile remove after convert encoding appended by Y.Kawada
392 if (function_exists('PMA_kanji_file_conv')
393 && (isset($textfile) && file_exists($textfile))) {
394 unlink($textfile);
397 // Counts the total number of rows for the same 'SELECT' query without the
398 // 'LIMIT' clause that may have been programatically added
400 if (empty($sql_limit_to_append)) {
401 $unlim_num_rows = $num_rows;
402 // if we did not append a limit, set this to get a correct
403 // "Showing rows..." message
404 $GLOBALS['session_max_rows'] = 'all';
405 } elseif ($is_select) {
407 // c o u n t q u e r y
409 // If we are "just browsing", there is only one table,
410 // and no where clause (or just 'WHERE 1 '),
411 // so we do a quick count (which uses MaxExactCount)
412 // because SQL_CALC_FOUND_ROWS
413 // is not quick on large InnoDB tables
415 // but do not count again if we did it previously
416 // due to $find_real_end == true
418 if (!$is_group
419 && !isset($analyzed_sql[0]['queryflags']['union'])
420 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
421 && (empty($analyzed_sql[0]['where_clause'])
422 || $analyzed_sql[0]['where_clause'] == '1 ')
423 && !isset($find_real_end)
426 // "j u s t b r o w s i n g"
427 $unlim_num_rows = PMA_Table::countRecords($db, $table, true);
429 } else { // n o t " j u s t b r o w s i n g "
431 if (PMA_MYSQL_INT_VERSION < 40000) {
433 // detect this case:
434 // SELECT DISTINCT x AS foo, y AS bar FROM sometable
436 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
437 $count_what = 'DISTINCT ';
438 $first_expr = true;
439 foreach ($analyzed_sql[0]['select_expr'] as $part) {
440 $count_what .= (!$first_expr ? ', ' : '') . $part['expr'];
441 $first_expr = false;
443 } else {
444 $count_what = '*';
446 // this one does not apply to VIEWs
447 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
450 // add the remaining of select expression if there is
451 // a GROUP BY or HAVING clause
452 if (PMA_MYSQL_INT_VERSION < 40000
453 && $count_what =='*'
454 && (!empty($analyzed_sql[0]['group_by_clause'])
455 || !empty($analyzed_sql[0]['having_clause']))) {
456 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
459 if (PMA_MYSQL_INT_VERSION >= 40000) {
460 // add select expression after the SQL_CALC_FOUND_ROWS
462 // for UNION, just adding SQL_CALC_FOUND_ROWS
463 // after the first SELECT works.
465 // take the left part, could be:
466 // SELECT
467 // (SELECT
468 $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
469 $count_query .= ' SQL_CALC_FOUND_ROWS ';
470 // add everything that was after the first SELECT
471 $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
472 // ensure there is no semicolon at the end of the
473 // count query because we'll probably add
474 // a LIMIT 1 clause after it
475 $count_query = rtrim($count_query);
476 $count_query = rtrim($count_query, ';');
477 } else { // PMA_MYSQL_INT_VERSION < 40000
479 if (!empty($analyzed_sql[0]['from_clause'])) {
480 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
482 if (!empty($analyzed_sql[0]['where_clause'])) {
483 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
485 if (!empty($analyzed_sql[0]['group_by_clause'])) {
486 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
488 if (!empty($analyzed_sql[0]['having_clause'])) {
489 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
491 } // end if
493 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
494 // long delays. Returned count will be complete anyway.
495 // (but a LIMIT would disrupt results in an UNION)
497 if (PMA_MYSQL_INT_VERSION >= 40000
498 && !isset($analyzed_sql[0]['queryflags']['union'])) {
499 $count_query .= ' LIMIT 1';
502 // run the count query
504 if (PMA_MYSQL_INT_VERSION < 40000) {
505 if ($cnt_all_result = PMA_DBI_try_query($count_query)) {
506 if ($is_group && $count_what == '*') {
507 $unlim_num_rows = @PMA_DBI_num_rows($cnt_all_result);
508 } else {
509 $unlim_num_rows = PMA_DBI_fetch_assoc($cnt_all_result);
510 $unlim_num_rows = $unlim_num_rows['count'];
512 PMA_DBI_free_result($cnt_all_result);
513 } else {
514 if (PMA_DBI_getError()) {
516 // there are some cases where the generated
517 // count_query (for MySQL 3) is wrong,
518 // so we get here.
520 * @todo use a big unlimited query to get the correct
521 * number of rows (depending on a config variable?)
523 $unlim_num_rows = 0;
526 } else {
527 PMA_DBI_try_query($count_query);
528 // if (mysql_error()) {
529 // void.
530 // I tried the case
531 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
532 // UNION (SELECT `User`, `Host`, "%" AS "Db",
533 // `Select_priv`
534 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
535 // and although the generated count_query is wrong
536 // the SELECT FOUND_ROWS() work! (maybe it gets the
537 // count from the latest query that worked)
539 // another case where the count_query is wrong:
540 // SELECT COUNT(*), f1 from t1 group by f1
541 // and you click to sort on count(*)
542 // }
543 $cnt_all_result = PMA_DBI_query('SELECT FOUND_ROWS() as count;');
544 list($unlim_num_rows) = PMA_DBI_fetch_row($cnt_all_result);
545 @PMA_DBI_free_result($cnt_all_result);
547 } // end else "just browsing"
549 } else { // not $is_select
550 $unlim_num_rows = 0;
551 } // end rows total count
553 // garvin: if a table or database gets dropped, check column comments.
554 if (isset($purge) && $purge == '1') {
555 require_once './libraries/relation_cleanup.lib.php';
557 if (strlen($table) && strlen($db)) {
558 PMA_relationsCleanupTable($db, $table);
559 } elseif (strlen($db)) {
560 PMA_relationsCleanupDatabase($db);
561 } else {
562 // garvin: VOID. No DB/Table gets deleted.
563 } // end if relation-stuff
564 } // end if ($purge)
566 // garvin: If a column gets dropped, do relation magic.
567 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
568 && strlen($db) && strlen($table) && !empty($purgekey)) {
569 require_once './libraries/relation_cleanup.lib.php';
570 PMA_relationsCleanupColumn($db, $table, $purgekey);
572 } // end if column PMA_* purge
573 } // end else "didn't ask to see php code"
575 // No rows returned -> move back to the calling page
576 if ($num_rows < 1 || $is_affected) {
577 if ($is_delete) {
578 $message = $strDeletedRows . '&nbsp;' . $num_rows;
579 } elseif ($is_insert) {
580 if ($is_replace) {
581 /* For replace we get DELETED + INSERTED row count, so we have to call it affected */
582 $message = $strAffectedRows . '&nbsp;' . $num_rows;
583 } else {
584 $message = $strInsertedRows . '&nbsp;' . $num_rows;
586 $insert_id = PMA_DBI_insert_id();
587 if ($insert_id != 0) {
588 // insert_id is id of FIRST record inserted in one insert, so if we inserted multiple rows, we had to increment this
589 $message .= '[br]'.$strInsertedRowId . '&nbsp;' . ($insert_id + $num_rows - 1);
591 } elseif ($is_affected) {
592 $message = $strAffectedRows . '&nbsp;' . $num_rows;
594 // Ok, here is an explanation for the !$is_select.
595 // The form generated by sql_query_form.lib.php
596 // and db_sql.php has many submit buttons
597 // on the same form, and some confusion arises from the
598 // fact that $zero_rows is sent for every case.
599 // The $zero_rows containing $strSuccess and sent with
600 // the form should not have priority over
601 // errors like $strEmptyResultSet
602 } elseif (!empty($zero_rows) && !$is_select) {
603 $message = $zero_rows;
604 } elseif (!empty($GLOBALS['show_as_php'])) {
605 $message = $strShowingPhp;
606 } elseif (isset($GLOBALS['show_as_php'])) {
607 /* User disable showing as PHP, query is only displayed */
608 $message = $strShowingSQL;
609 } elseif (!empty($GLOBALS['validatequery'])) {
610 $message = $strValidateSQL;
611 } else {
612 $message = $strEmptyResultSet;
615 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
617 if ($is_gotofile) {
618 $goto = PMA_securePath($goto);
619 // Checks for a valid target script
620 $is_db = $is_table = false;
621 include 'libraries/db_table_exists.lib.php';
622 if (strpos($goto, 'tbl_') === 0 && ! $is_table) {
623 if (strlen($table)) {
624 $table = '';
626 $goto = 'db_sql.php';
628 if (strpos($goto, 'db_') === 0 && ! $is_db) {
629 if (strlen($db)) {
630 $db = '';
632 $goto = 'main.php';
634 // Loads to target script
635 if (strpos($goto, 'db_') === 0
636 || strpos($goto, 'tbl_') === 0) {
637 $js_to_run = 'functions.js';
639 if ($goto != 'main.php') {
640 require_once './libraries/header.inc.php';
642 $active_page = $goto;
643 require './' . $goto;
644 } else {
645 // avoid a redirect loop when last record was deleted
646 if ('sql.php' == $cfg['DefaultTabTable']) {
647 $goto = str_replace('sql.php','tbl_structure.php',$goto);
649 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
650 } // end else
651 exit();
652 } // end no rows returned
654 // At least one row is returned -> displays a table with results
655 else {
656 // Displays the headers
657 if (isset($show_query)) {
658 unset($show_query);
660 if (isset($printview) && $printview == '1') {
661 require_once './libraries/header_printview.inc.php';
662 } else {
663 $js_to_run = 'functions.js';
664 unset($message);
665 if (strlen($table)) {
666 require './libraries/tbl_common.php';
667 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
668 require './libraries/tbl_info.inc.php';
669 require './libraries/tbl_links.inc.php';
670 } elseif (strlen($db)) {
671 require './libraries/db_common.inc.php';
672 require './libraries/db_info.inc.php';
673 } else {
674 require './libraries/server_common.inc.php';
675 require './libraries/server_links.inc.php';
679 if (strlen($db)) {
680 require_once './libraries/relation.lib.php';
681 $cfgRelation = PMA_getRelationsParam();
684 // Gets the list of fields properties
685 if (isset($result) && $result) {
686 $fields_meta = PMA_DBI_get_fields_meta($result);
687 $fields_cnt = count($fields_meta);
690 // Display previous update query (from tbl_replace)
691 if (isset($disp_query) && $cfg['ShowSQL'] == true) {
692 $tmp_sql_query = $GLOBALS['sql_query'];
693 $GLOBALS['sql_query'] = $disp_query;
694 PMA_showMessage($disp_message);
695 $GLOBALS['sql_query'] = $tmp_sql_query;
698 // Displays the results in a table
699 require_once './libraries/display_tbl.lib.php';
700 if (empty($disp_mode)) {
701 // see the "PMA_setDisplayMode()" function in
702 // libraries/display_tbl.lib.php
703 $disp_mode = 'urdr111101';
705 if (!isset($dontlimitchars)) {
706 $dontlimitchars = 0;
709 // hide edit and delete links for information_schema
710 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
711 $disp_mode = 'nnnn110111';
714 PMA_displayTable($result, $disp_mode, $analyzed_sql);
715 PMA_DBI_free_result($result);
717 // BEGIN INDEX CHECK See if indexes should be checked.
718 if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) {
719 foreach ($selected as $idx => $tbl_name) {
720 $check = PMA_check_indexes($tbl_name);
721 if (! empty($check)) {
723 <table border="0" cellpadding="2" cellspacing="0">
724 <tr>
725 <td class="tblHeaders" colspan="7"><?php printf($strIndexWarningTable, urldecode($tbl_name)); ?></td>
726 </tr>
727 <?php echo $check; ?>
728 </table>
729 <?php
732 } // End INDEX CHECK
734 // Bookmark support if required
735 if ($disp_mode[7] == '1'
736 && (isset($cfg['Bookmark']) && ! empty($cfg['Bookmark']['db']) && ! empty($cfg['Bookmark']['table']) && empty($id_bookmark))
737 && !empty($sql_query)) {
738 echo "\n";
740 $goto = 'sql.php?'
741 . PMA_generate_common_url($db, $table)
742 . '&amp;pos=' . $pos
743 . '&amp;session_max_rows=' . $session_max_rows
744 . '&amp;disp_direction=' . $disp_direction
745 . '&amp;repeat_cells=' . $repeat_cells
746 . '&amp;dontlimitchars=' . $dontlimitchars
747 . '&amp;sql_query=' . urlencode($sql_query)
748 . '&amp;id_bookmark=1';
751 <form action="sql.php" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
752 <?php echo PMA_generate_common_hidden_inputs(); ?>
753 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
754 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
755 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
756 <input type="hidden" name="fields[query]" value="<?php echo urlencode(isset($complete_query) ? $complete_query : $sql_query); ?>" />
757 <fieldset>
758 <legend><?php
759 echo ($cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_bookmark.png" width="16" height="16" alt="' . $strBookmarkThis . '" />' : '')
760 . $strBookmarkThis;
762 </legend>
764 <div class="formelement">
765 <label for="fields_label_"><?php echo $strBookmarkLabel; ?>:</label>
766 <input type="text" id="fields_label_" name="fields[label]" value="" />
767 </div>
769 <div class="formelement">
770 <input type="checkbox" name="bkm_all_users" id="bkm_all_users" value="true" />
771 <label for="bkm_all_users"><?php echo $strBookmarkAllUsers; ?></label>
772 </div>
774 <div class="clearfloat"></div>
775 </fieldset>
776 <fieldset class="tblFooters">
777 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
778 </fieldset>
779 </form>
780 <?php
781 } // end bookmark support
783 // Do print the page if required
784 if (isset($printview) && $printview == '1') {
786 <script type="text/javascript">
787 //<![CDATA[
788 // Do print the page
789 window.onload = function()
791 if (typeof(window.print) != 'undefined') {
792 window.print();
795 //]]>
796 </script>
797 <?php
798 } // end print case
799 } // end rows returned
802 * Displays the footer
804 require_once './libraries/footer.inc.php';