Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / libraries / db_table_exists.lib.php
blobf2eaf6727e8a5cf6449f1b988959082c9d2fa07e
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 = @$GLOBALS['dbi']->selectDb($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 $response = PMA_Response::getInstance();
24 if ($response->isAjax()) {
25 $response->isSuccess(false);
26 $response->addJSON(
27 'message',
28 PMA_Message::error(__('No databases selected.'))
30 } else {
31 $url_params = array('reload' => 1);
32 if (isset($message)) {
33 $url_params['message'] = $message;
35 if (! empty($sql_query)) {
36 $url_params['sql_query'] = $sql_query;
38 if (isset($show_as_php)) {
39 $url_params['show_as_php'] = $show_as_php;
41 PMA_sendHeaderLocation(
42 $cfg['PmaAbsoluteUri'] . 'index.php'
43 . PMA_generate_common_url($url_params, '&')
46 exit;
49 } // end if (ensures db exists)
51 if (empty($is_table)
52 && !defined('PMA_SUBMIT_MULT')
53 && ! defined('TABLE_MAY_BE_ABSENT')
54 ) {
55 // Not a valid table name -> back to the db_sql.php
57 if (strlen($table)) {
58 $is_table = isset(PMA_Table::$cache[$db][$table]);
60 if (! $is_table) {
61 $_result = $GLOBALS['dbi']->tryQuery(
62 'SHOW TABLES LIKE \'' . PMA_Util::sqlAddSlashes($table, true)
63 . '\';',
64 null, PMA_DatabaseInterface::QUERY_STORE
66 $is_table = @$GLOBALS['dbi']->numRows($_result);
67 $GLOBALS['dbi']->freeResult($_result);
69 } else {
70 $is_table = false;
73 if (! $is_table) {
74 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
75 if (strlen($table)) {
76 // SHOW TABLES doesn't show temporary tables, so try select
77 // (as it can happen just in case temporary table, it should be
78 // fast):
80 /**
81 * @todo should this check really
82 * only happen if IS_TRANSFORMATION_WRAPPER?
84 $_result = $GLOBALS['dbi']->tryQuery(
85 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($table) . ';',
86 null,
87 PMA_DatabaseInterface::QUERY_STORE
89 $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result));
90 $GLOBALS['dbi']->freeResult($_result);
93 if (! $is_table) {
94 include './db_sql.php';
95 exit;
99 if (! $is_table) {
100 exit;
103 } // end if (ensures table exists)