Translated using Weblate (Albanian)
[phpmyadmin.git] / libraries / db_table_exists.inc.php
blobb4fc51021dd9ec683bb8df5b1be12af91626d59b
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 use PMA\libraries\Message;
10 use PMA\libraries\Response;
11 use PMA\libraries\URL;
13 if (! defined('PHPMYADMIN')) {
14 exit;
17 if (empty($is_db)) {
18 if (strlen($db) > 0) {
19 $is_db = @$GLOBALS['dbi']->selectDb($db);
20 } else {
21 $is_db = false;
24 if (! $is_db) {
25 // not a valid db name -> back to the welcome page
26 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
27 $response = Response::getInstance();
28 if ($response->isAjax()) {
29 $response->setRequestStatus(false);
30 $response->addJSON(
31 'message',
32 Message::error(__('No databases selected.'))
34 } else {
35 $url_params = array('reload' => 1);
36 if (isset($message)) {
37 $url_params['message'] = $message;
39 if (! empty($sql_query)) {
40 $url_params['sql_query'] = $sql_query;
42 if (isset($show_as_php)) {
43 $url_params['show_as_php'] = $show_as_php;
45 PMA_sendHeaderLocation(
46 './index.php'
47 . URL::getCommonRaw($url_params)
50 exit;
53 } // end if (ensures db exists)
55 if (empty($is_table)
56 && !defined('PMA_SUBMIT_MULT')
57 && !defined('TABLE_MAY_BE_ABSENT')
58 ) {
59 // Not a valid table name -> back to the db_sql.php
61 if (strlen($table) > 0) {
62 $is_table = $GLOBALS['dbi']->getCachedTableContent(array($db, $table), false);
64 if (! $is_table) {
65 $_result = $GLOBALS['dbi']->tryQuery(
66 'SHOW TABLES LIKE \''
67 . $GLOBALS['dbi']->escapeString($table) . '\';',
68 null, PMA\libraries\DatabaseInterface::QUERY_STORE
70 $is_table = @$GLOBALS['dbi']->numRows($_result);
71 $GLOBALS['dbi']->freeResult($_result);
73 } else {
74 $is_table = false;
77 if (! $is_table) {
78 if (!defined('IS_TRANSFORMATION_WRAPPER')) {
79 if (strlen($table) > 0) {
80 // SHOW TABLES doesn't show temporary tables, so try select
81 // (as it can happen just in case temporary table, it should be
82 // fast):
84 /**
85 * @todo should this check really
86 * only happen if IS_TRANSFORMATION_WRAPPER?
88 $_result = $GLOBALS['dbi']->tryQuery(
89 'SELECT COUNT(*) FROM ' . PMA\libraries\Util::backquote($table)
90 . ';',
91 null,
92 PMA\libraries\DatabaseInterface::QUERY_STORE
94 $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result));
95 $GLOBALS['dbi']->freeResult($_result);
98 if (! $is_table) {
99 include './db_sql.php';
100 exit;
104 if (! $is_table) {
105 exit;
108 } // end if (ensures table exists)