bug #2356433 [display] HeaderFlipType "fake" problems
[phpmyadmin/crack.git] / libraries / db_table_exists.lib.php
blob66c30e9ed36e83a46797ab7cc65962f851bf9dd5
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Ensure the database and the table exist (else move to the "parent" script)
5 * and display headers
7 * @version $Id$
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
16 require_once './libraries/Table.class.php';
18 if (empty($is_db)) {
19 if (strlen($db)) {
20 $is_db = @PMA_DBI_select_db($db);
21 } else {
22 $is_db = false;
25 if (! $is_db) {
26 // not a valid db name -> back to the welcome page
27 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
28 $url_params = array('reload' => 1);
29 if (isset($message)) {
30 $url_params['message'] = $message;
32 if (! empty($sql_query)) {
33 $url_params['sql_query'] = $sql_query;
35 if (isset($show_as_php)) {
36 $url_params['show_as_php'] = $show_as_php;
38 PMA_sendHeaderLocation(
39 $cfg['PmaAbsoluteUri'] . 'main.php'
40 . PMA_generate_common_url($url_params, '&'));
42 exit;
44 } // end if (ensures db exists)
46 if (empty($is_table) && !defined('PMA_SUBMIT_MULT')) {
47 // Not a valid table name -> back to the db_sql.php
49 if (strlen($table)) {
50 $is_table = isset(PMA_Table::$cache[$db][$table]);
52 if (! $is_table) {
53 $_result = PMA_DBI_try_query(
54 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
55 null, PMA_DBI_QUERY_STORE);
56 $is_table = @PMA_DBI_num_rows($_result);
57 PMA_DBI_free_result($_result);
59 } else {
60 $is_table = false;
63 if (! $is_table) {
64 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
65 if (strlen($table)) {
66 // SHOW TABLES doesn't show temporary tables, so try select
67 // (as it can happen just in case temporary table, it should be
68 // fast):
70 /**
71 * @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER?
73 $_result = PMA_DBI_try_query(
74 'SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, true) . '`;',
75 null, PMA_DBI_QUERY_STORE);
76 $is_table = ($_result && @PMA_DBI_num_rows($_result));
77 PMA_DBI_free_result($_result);
80 if (! $is_table) {
81 $url_params = array('reload' => 1, 'db' => $db);
82 if (isset($message)) {
83 $url_params['message'] = $message;
85 if (! empty($sql_query)) {
86 $url_params['sql_query'] = $sql_query;
88 if (isset($display_query)) {
89 $url_params['display_query'] = $display_query;
91 PMA_sendHeaderLocation(
92 $cfg['PmaAbsoluteUri'] . 'db_sql.php'
93 . PMA_generate_common_url($url_params, '&'));
97 if (! $is_table) {
98 exit;
101 } // end if (ensures table exists)