Translated using Weblate (Hindi)
[phpmyadmin.git] / libraries / db_table_exists.inc.php
blob4a05f5f71d7887fe960a65d880dd907ea764a23d
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 */
10 use PhpMyAdmin\Core;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Url;
15 if (! defined('PHPMYADMIN')) {
16 exit;
19 if (empty($is_db)) {
20 if (strlen($db) > 0) {
21 $is_db = @$GLOBALS['dbi']->selectDb($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 $response = Response::getInstance();
30 if ($response->isAjax()) {
31 $response->setRequestStatus(false);
32 $response->addJSON(
33 'message',
34 Message::error(__('No databases selected.'))
36 } else {
37 $url_params = array('reload' => 1);
38 if (isset($message)) {
39 $url_params['message'] = $message;
41 if (! empty($sql_query)) {
42 $url_params['sql_query'] = $sql_query;
44 if (isset($show_as_php)) {
45 $url_params['show_as_php'] = $show_as_php;
47 Core::sendHeaderLocation(
48 './index.php'
49 . Url::getCommonRaw($url_params)
52 exit;
55 } // end if (ensures db exists)
57 if (empty($is_table)
58 && !defined('PMA_SUBMIT_MULT')
59 && !defined('TABLE_MAY_BE_ABSENT')
60 ) {
61 // Not a valid table name -> back to the db_sql.php
63 if (strlen($table) > 0) {
64 $is_table = $GLOBALS['dbi']->getCachedTableContent(array($db, $table), false);
66 if (! $is_table) {
67 $_result = $GLOBALS['dbi']->tryQuery(
68 'SHOW TABLES LIKE \''
69 . $GLOBALS['dbi']->escapeString($table) . '\';',
70 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
71 PhpMyAdmin\DatabaseInterface::QUERY_STORE
73 $is_table = @$GLOBALS['dbi']->numRows($_result);
74 $GLOBALS['dbi']->freeResult($_result);
76 } else {
77 $is_table = false;
80 if (! $is_table) {
81 if (!defined('IS_TRANSFORMATION_WRAPPER')) {
82 if (strlen($table) > 0) {
83 // SHOW TABLES doesn't show temporary tables, so try select
84 // (as it can happen just in case temporary table, it should be
85 // fast):
87 /**
88 * @todo should this check really
89 * only happen if IS_TRANSFORMATION_WRAPPER?
91 $_result = $GLOBALS['dbi']->tryQuery(
92 'SELECT COUNT(*) FROM ' . PhpMyAdmin\Util::backquote($table)
93 . ';',
94 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
95 PhpMyAdmin\DatabaseInterface::QUERY_STORE
97 $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result));
98 $GLOBALS['dbi']->freeResult($_result);
101 if (! $is_table) {
102 include './db_sql.php';
103 exit;
107 if (! $is_table) {
108 exit;
111 } // end if (ensures table exists)