Translated using Weblate (Bulgarian)
[phpmyadmin.git] / libraries / db_table_exists.inc.php
blob4e6e3694e9e174303d5695248eb101d0e7e20b19
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 declare(strict_types=1);
11 use PhpMyAdmin\Core;
12 use PhpMyAdmin\Message;
13 use PhpMyAdmin\Response;
14 use PhpMyAdmin\Url;
16 if (! defined('PHPMYADMIN')) {
17 exit;
20 global $db, $table;
22 if (empty($is_db)) {
23 if (strlen($db) > 0) {
24 $is_db = @$GLOBALS['dbi']->selectDb($db);
25 } else {
26 $is_db = false;
29 if (! $is_db) {
30 // not a valid db name -> back to the welcome page
31 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
32 $response = Response::getInstance();
33 if ($response->isAjax()) {
34 $response->setRequestStatus(false);
35 $response->addJSON(
36 'message',
37 Message::error(__('No databases selected.'))
39 } else {
40 $url_params = ['reload' => 1];
41 if (isset($message)) {
42 $url_params['message'] = $message;
44 if (! empty($sql_query)) {
45 $url_params['sql_query'] = $sql_query;
47 if (isset($show_as_php)) {
48 $url_params['show_as_php'] = $show_as_php;
50 Core::sendHeaderLocation(
51 './index.php'
52 . Url::getCommonRaw($url_params)
55 exit;
58 } // end if (ensures db exists)
60 if (empty($is_table)
61 && ! defined('PMA_SUBMIT_MULT')
62 && ! defined('TABLE_MAY_BE_ABSENT')
63 ) {
64 // Not a valid table name -> back to the db_sql.php
66 if (strlen($table) > 0) {
67 $is_table = $GLOBALS['dbi']->getCachedTableContent([$db, $table], false);
69 if (! $is_table) {
70 $_result = $GLOBALS['dbi']->tryQuery(
71 'SHOW TABLES LIKE \''
72 . $GLOBALS['dbi']->escapeString($table) . '\';',
73 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
74 PhpMyAdmin\DatabaseInterface::QUERY_STORE
76 $is_table = @$GLOBALS['dbi']->numRows($_result);
77 $GLOBALS['dbi']->freeResult($_result);
79 } else {
80 $is_table = false;
83 if (! $is_table) {
84 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
85 if (strlen($table) > 0) {
86 // SHOW TABLES doesn't show temporary tables, so try select
87 // (as it can happen just in case temporary table, it should be
88 // fast):
90 /**
91 * @todo should this check really
92 * only happen if IS_TRANSFORMATION_WRAPPER?
94 $_result = $GLOBALS['dbi']->tryQuery(
95 'SELECT COUNT(*) FROM ' . PhpMyAdmin\Util::backquote($table)
96 . ';',
97 PhpMyAdmin\DatabaseInterface::CONNECT_USER,
98 PhpMyAdmin\DatabaseInterface::QUERY_STORE
100 $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result));
101 $GLOBALS['dbi']->freeResult($_result);
104 if (! $is_table) {
105 include ROOT_PATH . 'db_sql.php';
106 exit;
110 if (! $is_table) {
111 exit;
114 } // end if (ensures table exists)