fixed: bugID = 3112614
[phpmyadmin/adnan.git] / libraries / db_table_exists.lib.php
blob8eb93e46d8581d08c7e584e5a232dba9ceab6969
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 * @package phpMyAdmin
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 if (empty($is_db)) {
14 if (strlen($db)) {
15 $is_db = @PMA_DBI_select_db($db);
16 } else {
17 $is_db = false;
20 if (! $is_db) {
21 // not a valid db name -> back to the welcome page
22 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
23 $url_params = array('reload' => 1);
24 if (isset($message)) {
25 $url_params['message'] = $message;
27 if (! empty($sql_query)) {
28 $url_params['sql_query'] = $sql_query;
30 if (isset($show_as_php)) {
31 $url_params['show_as_php'] = $show_as_php;
33 PMA_sendHeaderLocation(
34 $cfg['PmaAbsoluteUri'] . 'main.php'
35 . PMA_generate_common_url($url_params, '&'));
37 exit;
39 } // end if (ensures db exists)
41 if (empty($is_table) && !defined('PMA_SUBMIT_MULT') && ! defined('TABLE_MAY_BE_ABSENT')) {
42 // Not a valid table name -> back to the db_sql.php
44 if (strlen($table)) {
45 $is_table = isset(PMA_Table::$cache[$db][$table]);
47 if (! $is_table) {
48 $_result = PMA_DBI_try_query(
49 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
50 null, PMA_DBI_QUERY_STORE);
51 $is_table = @PMA_DBI_num_rows($_result);
52 PMA_DBI_free_result($_result);
54 } else {
55 $is_table = false;
58 if (! $is_table) {
59 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
60 if (strlen($table)) {
61 // SHOW TABLES doesn't show temporary tables, so try select
62 // (as it can happen just in case temporary table, it should be
63 // fast):
65 /**
66 * @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER?
68 $_result = PMA_DBI_try_query(
69 'SELECT COUNT(*) FROM ' . PMA_backquote($table) . ';',
70 null, PMA_DBI_QUERY_STORE);
71 $is_table = ($_result && @PMA_DBI_num_rows($_result));
72 PMA_DBI_free_result($_result);
75 if (! $is_table) {
76 require './db_sql.php';
77 exit;
81 if (! $is_table) {
82 exit;
85 } // end if (ensures table exists)