bug #2042032 Cannot detect PmaAbsoluteUri correctly on Windows
[phpmyadmin/madhuracj.git] / libraries / db_table_exists.lib.php
blobd1ae16a344d742fd862c76d48564a463990e2cb0
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 * @package phpMyAdmin
9 */
10 if (! defined('PHPMYADMIN')) {
11 exit;
14 /**
17 require_once './libraries/Table.class.php';
19 if (empty($is_db)) {
20 if (strlen($db)) {
21 $is_db = @PMA_DBI_select_db($db);
22 } else {
23 $is_db = false;
26 if (! $is_db) {
27 // not a valid db name -> back to the welcome page
28 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
29 $url_params = array('reload' => 1);
30 if (isset($message)) {
31 $url_params['message'] = $message;
33 if (! empty($sql_query)) {
34 $url_params['sql_query'] = $sql_query;
36 if (isset($show_as_php)) {
37 $url_params['show_as_php'] = $show_as_php;
39 PMA_sendHeaderLocation(
40 $cfg['PmaAbsoluteUri'] . 'main.php'
41 . PMA_generate_common_url($url_params, '&'));
43 exit;
45 } // end if (ensures db exists)
47 if (empty($is_table) && !defined('PMA_SUBMIT_MULT') && ! defined('TABLE_MAY_BE_ABSENT')) {
48 // Not a valid table name -> back to the db_sql.php
50 if (strlen($table)) {
51 $is_table = isset(PMA_Table::$cache[$db][$table]);
53 if (! $is_table) {
54 $_result = PMA_DBI_try_query(
55 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
56 null, PMA_DBI_QUERY_STORE);
57 $is_table = @PMA_DBI_num_rows($_result);
58 PMA_DBI_free_result($_result);
60 } else {
61 $is_table = false;
64 if (! $is_table) {
65 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
66 if (strlen($table)) {
67 // SHOW TABLES doesn't show temporary tables, so try select
68 // (as it can happen just in case temporary table, it should be
69 // fast):
71 /**
72 * @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER?
74 $_result = PMA_DBI_try_query(
75 'SELECT COUNT(*) FROM ' . PMA_backquote($table) . ';',
76 null, PMA_DBI_QUERY_STORE);
77 $is_table = ($_result && @PMA_DBI_num_rows($_result));
78 PMA_DBI_free_result($_result);
81 if (! $is_table) {
82 require 'db_sql.php';
83 exit;
87 if (! $is_table) {
88 exit;
91 } // end if (ensures table exists)