2.11.1.2 release
[phpmyadmin/arisferyanto.git] / sql.php
blobd6808a3e281f9ca9e22ffeb870e9271a148184a0
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 * Defines the url to return to in case of error in a sql statement
21 // Security checkings
22 if (!empty($goto)) {
23 $is_gotofile = preg_replace('@^([^?]+).*$@s', '\\1', $goto);
24 if (!@file_exists('./' . $is_gotofile)) {
25 unset($goto);
26 } else {
27 $is_gotofile = ($is_gotofile == $goto);
29 } // end if (security checkings)
31 if (empty($goto)) {
32 $goto = (! strlen($table)) ? $cfg['DefaultTabDatabase'] : $cfg['DefaultTabTable'];
33 $is_gotofile = true;
34 } // end if
35 if (!isset($err_url)) {
36 $err_url = (!empty($back) ? $back : $goto)
37 . '?' . PMA_generate_common_url($db)
38 . ((strpos(' ' . $goto, 'db_') != 1 && strlen($table)) ? '&amp;table=' . urlencode($table) : '');
39 } // end if
41 // Coming from a bookmark dialog
42 if (isset($fields['query'])) {
43 $sql_query = $fields['query'];
46 // This one is just to fill $db
47 if (isset($fields['dbase'])) {
48 $db = $fields['dbase'];
51 // Default to browse if no query set an we have table
52 // (needed for browsing from DefaultTabTable)
53 if (empty($sql_query) && strlen($table) && strlen($db)) {
54 require_once './libraries/bookmark.lib.php';
55 $book_sql_query = PMA_queryBookmarks($db,
56 $GLOBALS['cfg']['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'',
57 'label');
59 if (! empty($book_sql_query)) {
60 $sql_query = $book_sql_query;
61 } else {
62 $sql_query = 'SELECT * FROM ' . PMA_backquote($table);
64 unset($book_sql_query);
66 // set $goto to what will be displayed if query returns 0 rows
67 $goto = 'tbl_structure.php';
68 } else {
69 // Now we can check the parameters
70 PMA_checkParameters(array('sql_query'));
73 // instead of doing the test twice
74 $is_drop_database = preg_match('/DROP[[:space:]]+(DATABASE|SCHEMA)[[:space:]]+/i',
75 $sql_query);
77 /**
78 * Check rights in case of DROP DATABASE
80 * This test may be bypassed if $is_js_confirmed = 1 (already checked with js)
81 * but since a malicious user may pass this variable by url/form, we don't take
82 * into account this case.
84 if (!defined('PMA_CHK_DROP')
85 && !$cfg['AllowUserDropDatabase']
86 && $is_drop_database
87 && !$is_superuser) {
88 require_once './libraries/header.inc.php';
89 PMA_mysqlDie($strNoDropDatabases, '', '', $err_url);
90 } // end if
92 require_once './libraries/display_tbl.lib.php';
93 PMA_displayTable_checkConfigParams();
95 /**
96 * Need to find the real end of rows?
98 if (isset($find_real_end) && $find_real_end) {
99 $unlim_num_rows = PMA_Table::countRecords($db, $table, true, true);
100 $_SESSION['userconf']['pos'] = @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']) - 1) * $_SESSION['userconf']['max_rows']);
105 * Bookmark add
107 if (isset($store_bkm)) {
108 PMA_addBookmarks($fields, $cfg['Bookmark'], (isset($bkm_all_users) && $bkm_all_users == 'true' ? true : false));
109 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . $goto);
110 } // end if
114 * Gets the true sql query
116 // $sql_query has been urlencoded in the confirmation form for drop/delete
117 // queries or in the navigation bar for browsing among records
118 if (isset($btnDrop) || isset($navig)) {
119 $sql_query = urldecode($sql_query);
123 * Parse and analyze the query
125 require_once './libraries/parse_analyze.lib.php';
128 * Sets or modifies the $goto variable if required
130 if ($goto == 'sql.php') {
131 $is_gotofile = false;
132 $goto = 'sql.php?'
133 . PMA_generate_common_url($db, $table)
134 . '&amp;sql_query=' . urlencode($sql_query);
135 } // end if
139 * Go back to further page if table should not be dropped
141 if (isset($btnDrop) && $btnDrop == $strNo) {
142 if (!empty($back)) {
143 $goto = $back;
145 if ($is_gotofile) {
146 if (strpos(' ' . $goto, 'db_') == 1 && strlen($table)) {
147 $table = '';
149 $active_page = $goto;
150 require './' . PMA_securePath($goto);
151 } else {
152 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto));
154 exit();
155 } // end if
159 * Displays the confirm page if required
161 * This part of the script is bypassed if $is_js_confirmed = 1 (already checked
162 * with js) because possible security issue is not so important here: at most,
163 * the confirm message isn't displayed.
165 * Also bypassed if only showing php code.or validating a SQL query
167 if (! $cfg['Confirm'] || isset($_REQUEST['is_js_confirmed']) || isset($btnDrop)
168 // if we are coming from a "Create PHP code" or a "Without PHP Code"
169 // dialog, we won't execute the query anyway, so don't confirm
170 //|| !empty($GLOBALS['show_as_php'])
171 || isset($GLOBALS['show_as_php'])
172 || !empty($GLOBALS['validatequery'])) {
173 $do_confirm = false;
174 } else {
175 $do_confirm = isset($analyzed_sql[0]['queryflags']['need_confirm']);
178 if ($do_confirm) {
179 $stripped_sql_query = $sql_query;
180 require_once './libraries/header.inc.php';
181 if ($is_drop_database) {
182 echo '<h1 class="warning">' . $strDropDatabaseStrongWarning . '</h1>';
184 echo '<form action="sql.php" method="post">' . "\n"
185 .PMA_generate_common_hidden_inputs($db, $table);
187 <input type="hidden" name="sql_query" value="<?php echo urlencode($sql_query); ?>" />
188 <input type="hidden" name="zero_rows" value="<?php echo isset($zero_rows) ? PMA_sanitize($zero_rows) : ''; ?>" />
189 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
190 <input type="hidden" name="back" value="<?php echo isset($back) ? PMA_sanitize($back) : ''; ?>" />
191 <input type="hidden" name="reload" value="<?php echo isset($reload) ? PMA_sanitize($reload) : 0; ?>" />
192 <input type="hidden" name="purge" value="<?php echo isset($purge) ? PMA_sanitize($purge) : ''; ?>" />
193 <input type="hidden" name="cpurge" value="<?php echo isset($cpurge) ? PMA_sanitize($cpurge) : ''; ?>" />
194 <input type="hidden" name="purgekey" value="<?php echo isset($purgekey) ? PMA_sanitize($purgekey) : ''; ?>" />
195 <input type="hidden" name="show_query" value="<?php echo isset($show_query) ? PMA_sanitize($show_query) : ''; ?>" />
196 <?php
197 echo '<fieldset class="confirmation">' . "\n"
198 .' <legend>' . $strDoYouReally . '</legend>'
199 .' <tt>' . htmlspecialchars($stripped_sql_query) . '</tt>' . "\n"
200 .'</fieldset>' . "\n"
201 .'<fieldset class="tblFooters">' . "\n";
203 <input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" id="buttonYes" />
204 <input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" id="buttonNo" />
205 <?php
206 echo '</fieldset>' . "\n"
207 . '</form>' . "\n";
210 * Displays the footer and exit
212 require_once './libraries/footer.inc.php';
213 } // end if $do_confirm
216 // Defines some variables
217 // A table has to be created or renamed -> left frame should be reloaded
219 * @todo use the parser/analyzer
222 if (empty($reload)
223 && preg_match('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
224 $reload = 1;
227 // SK -- Patch: $is_group added for use in calculation of total number of
228 // rows.
229 // $is_count is changed for more correct "LIMIT" clause
230 // appending in queries like
231 // "SELECT COUNT(...) FROM ... GROUP BY ..."
234 * @todo detect all this with the parser, to avoid problems finding
235 * those strings in comments or backquoted identifiers
238 $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;
239 if ($is_select) { // see line 141
240 $is_group = preg_match('@(GROUP[[:space:]]+BY|HAVING|SELECT[[:space:]]+DISTINCT)[[:space:]]+@i', $sql_query);
241 $is_func = !$is_group && (preg_match('@[[:space:]]+(SUM|AVG|STD|STDDEV|MIN|MAX|BIT_OR|BIT_AND)\s*\(@i', $sql_query));
242 $is_count = !$is_group && (preg_match('@^SELECT[[:space:]]+COUNT\((.*\.+)?.*\)@i', $sql_query));
243 $is_export = (preg_match('@[[:space:]]+INTO[[:space:]]+OUTFILE[[:space:]]+@i', $sql_query));
244 $is_analyse = (preg_match('@[[:space:]]+PROCEDURE[[:space:]]+ANALYSE@i', $sql_query));
245 } elseif (preg_match('@^EXPLAIN[[:space:]]+@i', $sql_query)) {
246 $is_explain = true;
247 } elseif (preg_match('@^DELETE[[:space:]]+@i', $sql_query)) {
248 $is_delete = true;
249 $is_affected = true;
250 } elseif (preg_match('@^(INSERT|LOAD[[:space:]]+DATA|REPLACE)[[:space:]]+@i', $sql_query)) {
251 $is_insert = true;
252 $is_affected = true;
253 if (preg_match('@^(REPLACE)[[:space:]]+@i', $sql_query)) {
254 $is_replace = true;
256 } elseif (preg_match('@^UPDATE[[:space:]]+@i', $sql_query)) {
257 $is_affected = true;
258 } elseif (preg_match('@^SHOW[[:space:]]+@i', $sql_query)) {
259 $is_show = true;
260 } elseif (preg_match('@^(CHECK|ANALYZE|REPAIR|OPTIMIZE)[[:space:]]+TABLE[[:space:]]+@i', $sql_query)) {
261 $is_maint = true;
264 // Do append a "LIMIT" clause?
265 if ((!$cfg['ShowAll'] || $_SESSION['userconf']['max_rows'] != 'all')
266 && !($is_count || $is_export || $is_func || $is_analyse)
267 && isset($analyzed_sql[0]['queryflags']['select_from'])
268 && !isset($analyzed_sql[0]['queryflags']['offset'])
269 && !preg_match('@[[:space:]]LIMIT[[:space:]0-9,-]+(;)?$@i', $sql_query)
271 $sql_limit_to_append = ' LIMIT ' . $_SESSION['userconf']['pos'] . ', ' . $_SESSION['userconf']['max_rows'] . " ";
273 $full_sql_query = $analyzed_sql[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_sql[0]['section_after_limit'];
275 * @todo pretty printing of this modified query
277 if (isset($display_query)) {
278 // if the analysis of the original query revealed that we found
279 // a section_after_limit, we now have to analyze $display_query
280 // to display it correctly
282 if (!empty($analyzed_sql[0]['section_after_limit']) && trim($analyzed_sql[0]['section_after_limit']) != ';') {
283 $analyzed_display_query = PMA_SQP_analyze(PMA_SQP_parse($display_query));
284 $display_query = $analyzed_display_query[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_display_query[0]['section_after_limit'];
288 } else {
289 $full_sql_query = $sql_query;
290 } // end if...else
292 if (strlen($db)) {
293 PMA_DBI_select_db($db);
296 // If the query is a DELETE query with no WHERE clause, get the number of
297 // rows that will be deleted (mysql_affected_rows will always return 0 in
298 // this case)
299 // Note: testing shows that this no longer applies since MySQL 4.0.x
301 if (PMA_MYSQL_INT_VERSION < 40000) {
302 if ($is_delete
303 && preg_match('@^DELETE([[:space:]].+)?(FROM[[:space:]](.+))$@i', $sql_query, $parts)
304 && !preg_match('@[[:space:]]WHERE[[:space:]]@i', $parts[3])) {
305 $cnt_all_result = @PMA_DBI_try_query('SELECT COUNT(*) as count ' . $parts[2]);
306 if ($cnt_all_result) {
307 list($num_rows) = PMA_DBI_fetch_row($cnt_all_result);
308 PMA_DBI_free_result($cnt_all_result);
309 } else {
310 $num_rows = 0;
315 // E x e c u t e t h e q u e r y
317 // Only if we didn't ask to see the php code (mikebeck)
318 if (isset($GLOBALS['show_as_php']) || !empty($GLOBALS['validatequery'])) {
319 unset($result);
320 $num_rows = 0;
321 } else {
322 if (isset($_SESSION['profiling'])) {
323 PMA_DBI_query('SET PROFILING=1;');
326 // garvin: Measure query time.
327 // TODO-Item http://sourceforge.net/tracker/index.php?func=detail&aid=571934&group_id=23067&atid=377411
328 $querytime_before = array_sum(explode(' ', microtime()));
330 $result = @PMA_DBI_try_query($full_sql_query, null, PMA_DBI_QUERY_STORE);
332 $querytime_after = array_sum(explode(' ', microtime()));
334 $GLOBALS['querytime'] = $querytime_after - $querytime_before;
336 // Displays an error message if required and stop parsing the script
337 if ($error = PMA_DBI_getError()) {
338 require_once './libraries/header.inc.php';
339 $full_err_url = (preg_match('@^(db|tbl)_@', $err_url))
340 ? $err_url . '&amp;show_query=1&amp;sql_query=' . urlencode($sql_query)
341 : $err_url;
342 PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
344 unset($error);
346 // Gets the number of rows affected/returned
347 // (This must be done immediately after the query because
348 // mysql_affected_rows() reports about the last query done)
350 if (!$is_affected) {
351 $num_rows = ($result) ? @PMA_DBI_num_rows($result) : 0;
352 } elseif (!isset($num_rows)) {
353 $num_rows = @PMA_DBI_affected_rows();
356 // Grabs the profiling results
357 if (isset($_SESSION['profiling'])) {
358 $profiling_results = PMA_DBI_fetch_result('SHOW PROFILE;');
361 // Checks if the current database has changed
362 // This could happen if the user sends a query like "USE `database`;"
363 $res = PMA_DBI_query('SELECT DATABASE() AS \'db\';');
364 $row = PMA_DBI_fetch_row($res);
365 if (strlen($db) && is_array($row) && isset($row[0]) && (strcasecmp($db, $row[0]) != 0)) {
366 $db = $row[0];
367 $reload = 1;
369 @PMA_DBI_free_result($res);
370 unset($res, $row);
372 // tmpfile remove after convert encoding appended by Y.Kawada
373 if (function_exists('PMA_kanji_file_conv')
374 && (isset($textfile) && file_exists($textfile))) {
375 unlink($textfile);
378 // Counts the total number of rows for the same 'SELECT' query without the
379 // 'LIMIT' clause that may have been programatically added
381 if (empty($sql_limit_to_append)) {
382 $unlim_num_rows = $num_rows;
383 // if we did not append a limit, set this to get a correct
384 // "Showing rows..." message
385 //$_SESSION['userconf']['max_rows'] = 'all';
386 } elseif ($is_select) {
388 // c o u n t q u e r y
390 // If we are "just browsing", there is only one table,
391 // and no where clause (or just 'WHERE 1 '),
392 // so we do a quick count (which uses MaxExactCount)
393 // because SQL_CALC_FOUND_ROWS
394 // is not quick on large InnoDB tables
396 // but do not count again if we did it previously
397 // due to $find_real_end == true
399 if (!$is_group
400 && !isset($analyzed_sql[0]['queryflags']['union'])
401 && !isset($analyzed_sql[0]['table_ref'][1]['table_name'])
402 && (empty($analyzed_sql[0]['where_clause'])
403 || $analyzed_sql[0]['where_clause'] == '1 ')
404 && !isset($find_real_end)
407 // "j u s t b r o w s i n g"
408 $unlim_num_rows = PMA_Table::countRecords($db, $table, true);
410 } else { // n o t " j u s t b r o w s i n g "
412 if (PMA_MYSQL_INT_VERSION < 40000) {
414 // detect this case:
415 // SELECT DISTINCT x AS foo, y AS bar FROM sometable
417 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
418 $count_what = 'DISTINCT ';
419 $first_expr = true;
420 foreach ($analyzed_sql[0]['select_expr'] as $part) {
421 $count_what .= (!$first_expr ? ', ' : '') . $part['expr'];
422 $first_expr = false;
424 } else {
425 $count_what = '*';
427 // this one does not apply to VIEWs
428 $count_query = 'SELECT COUNT(' . $count_what . ') AS count';
431 // add the remaining of select expression if there is
432 // a GROUP BY or HAVING clause
433 if (PMA_MYSQL_INT_VERSION < 40000
434 && $count_what =='*'
435 && (!empty($analyzed_sql[0]['group_by_clause'])
436 || !empty($analyzed_sql[0]['having_clause']))) {
437 $count_query .= ' ,' . $analyzed_sql[0]['select_expr_clause'];
440 if (PMA_MYSQL_INT_VERSION >= 40000) {
441 // add select expression after the SQL_CALC_FOUND_ROWS
443 // for UNION, just adding SQL_CALC_FOUND_ROWS
444 // after the first SELECT works.
446 // take the left part, could be:
447 // SELECT
448 // (SELECT
449 $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
450 $count_query .= ' SQL_CALC_FOUND_ROWS ';
451 // add everything that was after the first SELECT
452 $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select']+1);
453 // ensure there is no semicolon at the end of the
454 // count query because we'll probably add
455 // a LIMIT 1 clause after it
456 $count_query = rtrim($count_query);
457 $count_query = rtrim($count_query, ';');
458 } else { // PMA_MYSQL_INT_VERSION < 40000
460 if (!empty($analyzed_sql[0]['from_clause'])) {
461 $count_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
463 if (!empty($analyzed_sql[0]['where_clause'])) {
464 $count_query .= ' WHERE ' . $analyzed_sql[0]['where_clause'];
466 if (!empty($analyzed_sql[0]['group_by_clause'])) {
467 $count_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
469 if (!empty($analyzed_sql[0]['having_clause'])) {
470 $count_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
472 } // end if
474 // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
475 // long delays. Returned count will be complete anyway.
476 // (but a LIMIT would disrupt results in an UNION)
478 if (PMA_MYSQL_INT_VERSION >= 40000
479 && !isset($analyzed_sql[0]['queryflags']['union'])) {
480 $count_query .= ' LIMIT 1';
483 // run the count query
485 if (PMA_MYSQL_INT_VERSION < 40000) {
486 if ($cnt_all_result = PMA_DBI_try_query($count_query)) {
487 if ($is_group && $count_what == '*') {
488 $unlim_num_rows = @PMA_DBI_num_rows($cnt_all_result);
489 } else {
490 $unlim_num_rows = PMA_DBI_fetch_assoc($cnt_all_result);
491 $unlim_num_rows = $unlim_num_rows['count'];
493 PMA_DBI_free_result($cnt_all_result);
494 } else {
495 if (PMA_DBI_getError()) {
497 // there are some cases where the generated
498 // count_query (for MySQL 3) is wrong,
499 // so we get here.
501 * @todo use a big unlimited query to get the correct
502 * number of rows (depending on a config variable?)
504 $unlim_num_rows = 0;
507 } else {
508 PMA_DBI_try_query($count_query);
509 // if (mysql_error()) {
510 // void.
511 // I tried the case
512 // (SELECT `User`, `Host`, `Db`, `Select_priv` FROM `db`)
513 // UNION (SELECT `User`, `Host`, "%" AS "Db",
514 // `Select_priv`
515 // FROM `user`) ORDER BY `User`, `Host`, `Db`;
516 // and although the generated count_query is wrong
517 // the SELECT FOUND_ROWS() work! (maybe it gets the
518 // count from the latest query that worked)
520 // another case where the count_query is wrong:
521 // SELECT COUNT(*), f1 from t1 group by f1
522 // and you click to sort on count(*)
523 // }
524 $cnt_all_result = PMA_DBI_query('SELECT FOUND_ROWS() as count;');
525 list($unlim_num_rows) = PMA_DBI_fetch_row($cnt_all_result);
526 @PMA_DBI_free_result($cnt_all_result);
528 } // end else "just browsing"
530 } else { // not $is_select
531 $unlim_num_rows = 0;
532 } // end rows total count
534 // garvin: if a table or database gets dropped, check column comments.
535 if (isset($purge) && $purge == '1') {
536 require_once './libraries/relation_cleanup.lib.php';
538 if (strlen($table) && strlen($db)) {
539 PMA_relationsCleanupTable($db, $table);
540 } elseif (strlen($db)) {
541 PMA_relationsCleanupDatabase($db);
542 } else {
543 // garvin: VOID. No DB/Table gets deleted.
544 } // end if relation-stuff
545 } // end if ($purge)
547 // garvin: If a column gets dropped, do relation magic.
548 if (isset($cpurge) && $cpurge == '1' && isset($purgekey)
549 && strlen($db) && strlen($table) && !empty($purgekey)) {
550 require_once './libraries/relation_cleanup.lib.php';
551 PMA_relationsCleanupColumn($db, $table, $purgekey);
553 } // end if column PMA_* purge
554 } // end else "didn't ask to see php code"
556 // No rows returned -> move back to the calling page
557 if ($num_rows < 1 || $is_affected) {
558 if ($is_delete) {
559 $message = $strDeletedRows . '&nbsp;' . $num_rows;
560 } elseif ($is_insert) {
561 if ($is_replace) {
562 /* For replace we get DELETED + INSERTED row count, so we have to call it affected */
563 $message = $strAffectedRows . '&nbsp;' . $num_rows;
564 } else {
565 $message = $strInsertedRows . '&nbsp;' . $num_rows;
567 $insert_id = PMA_DBI_insert_id();
568 if ($insert_id != 0) {
569 // insert_id is id of FIRST record inserted in one insert, so if we inserted multiple rows, we had to increment this
570 $message .= '[br]'.$strInsertedRowId . '&nbsp;' . ($insert_id + $num_rows - 1);
572 } elseif ($is_affected) {
573 $message = $strAffectedRows . '&nbsp;' . $num_rows;
575 // Ok, here is an explanation for the !$is_select.
576 // The form generated by sql_query_form.lib.php
577 // and db_sql.php has many submit buttons
578 // on the same form, and some confusion arises from the
579 // fact that $zero_rows is sent for every case.
580 // The $zero_rows containing $strSuccess and sent with
581 // the form should not have priority over
582 // errors like $strEmptyResultSet
583 } elseif (!empty($zero_rows) && !$is_select) {
584 $message = $zero_rows;
585 } elseif (!empty($GLOBALS['show_as_php'])) {
586 $message = $strShowingPhp;
587 } elseif (isset($GLOBALS['show_as_php'])) {
588 /* User disable showing as PHP, query is only displayed */
589 $message = $strShowingSQL;
590 } elseif (!empty($GLOBALS['validatequery'])) {
591 $message = $strValidateSQL;
592 } else {
593 $message = $strEmptyResultSet;
596 $message .= ' ' . (isset($GLOBALS['querytime']) ? '(' . sprintf($strQueryTime, $GLOBALS['querytime']) . ')' : '');
598 if ($is_gotofile) {
599 $goto = PMA_securePath($goto);
600 // Checks for a valid target script
601 $is_db = $is_table = false;
602 include 'libraries/db_table_exists.lib.php';
603 if (strpos($goto, 'tbl_') === 0 && ! $is_table) {
604 if (strlen($table)) {
605 $table = '';
607 $goto = 'db_sql.php';
609 if (strpos($goto, 'db_') === 0 && ! $is_db) {
610 if (strlen($db)) {
611 $db = '';
613 $goto = 'main.php';
615 // Loads to target script
616 if (strpos($goto, 'db_') === 0
617 || strpos($goto, 'tbl_') === 0) {
618 $js_to_run = 'functions.js';
620 if ($goto != 'main.php') {
621 require_once './libraries/header.inc.php';
623 $active_page = $goto;
624 require './' . $goto;
625 } else {
626 // avoid a redirect loop when last record was deleted
627 if ('sql.php' == $cfg['DefaultTabTable']) {
628 $goto = str_replace('sql.php','tbl_structure.php',$goto);
630 PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . str_replace('&amp;', '&', $goto) . '&message=' . urlencode($message));
631 } // end else
632 exit();
633 } // end no rows returned
635 // At least one row is returned -> displays a table with results
636 else {
637 // Displays the headers
638 if (isset($show_query)) {
639 unset($show_query);
641 if (isset($printview) && $printview == '1') {
642 require_once './libraries/header_printview.inc.php';
643 } else {
644 $js_to_run = 'functions.js';
645 unset($message);
646 if (strlen($table)) {
647 require './libraries/tbl_common.php';
648 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
649 require './libraries/tbl_info.inc.php';
650 require './libraries/tbl_links.inc.php';
651 } elseif (strlen($db)) {
652 require './libraries/db_common.inc.php';
653 require './libraries/db_info.inc.php';
654 } else {
655 require './libraries/server_common.inc.php';
656 require './libraries/server_links.inc.php';
660 if (strlen($db)) {
661 require_once './libraries/relation.lib.php';
662 $cfgRelation = PMA_getRelationsParam();
665 // Gets the list of fields properties
666 if (isset($result) && $result) {
667 $fields_meta = PMA_DBI_get_fields_meta($result);
668 $fields_cnt = count($fields_meta);
671 // Display previous update query (from tbl_replace)
672 if (isset($disp_query) && $cfg['ShowSQL'] == true) {
673 $tmp_sql_query = $GLOBALS['sql_query'];
674 $GLOBALS['sql_query'] = $disp_query;
675 PMA_showMessage($disp_message);
676 $GLOBALS['sql_query'] = $tmp_sql_query;
679 if (isset($profiling_results)) {
680 PMA_profilingResults($profiling_results);
683 // Displays the results in a table
684 if (empty($disp_mode)) {
685 // see the "PMA_setDisplayMode()" function in
686 // libraries/display_tbl.lib.php
687 $disp_mode = 'urdr111101';
690 // hide edit and delete links for information_schema
691 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
692 $disp_mode = 'nnnn110111';
695 PMA_displayTable($result, $disp_mode, $analyzed_sql);
696 PMA_DBI_free_result($result);
698 // BEGIN INDEX CHECK See if indexes should be checked.
699 if (isset($query_type) && $query_type == 'check_tbl' && isset($selected) && is_array($selected)) {
700 foreach ($selected as $idx => $tbl_name) {
701 $check = PMA_check_indexes($tbl_name);
702 if (! empty($check)) {
704 <table border="0" cellpadding="2" cellspacing="0">
705 <tr>
706 <td class="tblHeaders" colspan="7"><?php printf($strIndexWarningTable, urldecode($tbl_name)); ?></td>
707 </tr>
708 <?php echo $check; ?>
709 </table>
710 <?php
713 } // End INDEX CHECK
715 // Bookmark support if required
716 if ($disp_mode[7] == '1'
717 && (isset($cfg['Bookmark']) && ! empty($cfg['Bookmark']['db']) && ! empty($cfg['Bookmark']['table']) && empty($id_bookmark))
718 && !empty($sql_query)) {
719 echo "\n";
721 $goto = 'sql.php?'
722 . PMA_generate_common_url($db, $table)
723 . '&amp;sql_query=' . urlencode($sql_query)
724 . '&amp;id_bookmark=1';
727 <form action="sql.php" method="post" onsubmit="return emptyFormElements(this, 'fields[label]');">
728 <?php echo PMA_generate_common_hidden_inputs(); ?>
729 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
730 <input type="hidden" name="fields[dbase]" value="<?php echo htmlspecialchars($db); ?>" />
731 <input type="hidden" name="fields[user]" value="<?php echo $cfg['Bookmark']['user']; ?>" />
732 <input type="hidden" name="fields[query]" value="<?php echo urlencode(isset($complete_query) ? $complete_query : $sql_query); ?>" />
733 <fieldset>
734 <legend><?php
735 echo ($cfg['PropertiesIconic'] ? '<img class="icon" src="' . $pmaThemeImage . 'b_bookmark.png" width="16" height="16" alt="' . $strBookmarkThis . '" />' : '')
736 . $strBookmarkThis;
738 </legend>
740 <div class="formelement">
741 <label for="fields_label_"><?php echo $strBookmarkLabel; ?>:</label>
742 <input type="text" id="fields_label_" name="fields[label]" value="" />
743 </div>
745 <div class="formelement">
746 <input type="checkbox" name="bkm_all_users" id="bkm_all_users" value="true" />
747 <label for="bkm_all_users"><?php echo $strBookmarkAllUsers; ?></label>
748 </div>
750 <div class="clearfloat"></div>
751 </fieldset>
752 <fieldset class="tblFooters">
753 <input type="submit" name="store_bkm" value="<?php echo $strBookmarkThis; ?>" />
754 </fieldset>
755 </form>
756 <?php
757 } // end bookmark support
759 // Do print the page if required
760 if (isset($printview) && $printview == '1') {
762 <script type="text/javascript">
763 //<![CDATA[
764 // Do print the page
765 window.onload = function()
767 if (typeof(window.print) != 'undefined') {
768 window.print();
771 //]]>
772 </script>
773 <?php
774 } // end print case
775 } // end rows returned
778 * Displays the footer
780 require_once './libraries/footer.inc.php';