Translated using Weblate (Armenian)
[phpmyadmin.git] / libraries / db_table_exists.lib.php
blobb95f227593c19b183ab156a22ba9415fd6f708de
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 /** @var PMA_String $pmaString */
14 $pmaString = $GLOBALS['PMA_String'];
15 if (empty($is_db)) {
16 if (/*overload*/mb_strlen($db)) {
17 $is_db = @$GLOBALS['dbi']->selectDb($db);
18 } else {
19 $is_db = false;
22 if (! $is_db) {
23 // not a valid db name -> back to the welcome page
24 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
25 $response = PMA_Response::getInstance();
26 if ($response->isAjax()) {
27 $response->isSuccess(false);
28 $response->addJSON(
29 'message',
30 PMA_Message::error(__('No databases selected.'))
32 } else {
33 $url_params = array('reload' => 1);
34 if (isset($message)) {
35 $url_params['message'] = $message;
37 if (! empty($sql_query)) {
38 $url_params['sql_query'] = $sql_query;
40 if (isset($show_as_php)) {
41 $url_params['show_as_php'] = $show_as_php;
43 PMA_sendHeaderLocation(
44 $cfg['PmaAbsoluteUri'] . 'index.php'
45 . PMA_URL_getCommon($url_params, 'text')
48 exit;
51 } // end if (ensures db exists)
53 if (empty($is_table)
54 && !defined('PMA_SUBMIT_MULT')
55 && !defined('TABLE_MAY_BE_ABSENT')
56 ) {
57 // Not a valid table name -> back to the db_sql.php
59 if (/*overload*/mb_strlen($table)) {
60 $is_table = $GLOBALS['dbi']->getCachedTableContent("${db}.${table}", false);
62 if (! $is_table) {
63 $_result = $GLOBALS['dbi']->tryQuery(
64 'SHOW TABLES LIKE \'' . PMA_Util::sqlAddSlashes($table, true)
65 . '\';',
66 null, PMA_DatabaseInterface::QUERY_STORE
68 $is_table = @$GLOBALS['dbi']->numRows($_result);
69 $GLOBALS['dbi']->freeResult($_result);
71 } else {
72 $is_table = false;
75 if (! $is_table) {
76 if (!defined('IS_TRANSFORMATION_WRAPPER')) {
77 if (/*overload*/mb_strlen($table)) {
78 // SHOW TABLES doesn't show temporary tables, so try select
79 // (as it can happen just in case temporary table, it should be
80 // fast):
82 /**
83 * @todo should this check really
84 * only happen if IS_TRANSFORMATION_WRAPPER?
86 $_result = $GLOBALS['dbi']->tryQuery(
87 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($table) . ';',
88 null,
89 PMA_DatabaseInterface::QUERY_STORE
91 $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result));
92 $GLOBALS['dbi']->freeResult($_result);
95 if (! $is_table) {
96 include './db_sql.php';
97 exit;
101 if (! $is_table) {
102 exit;
105 } // end if (ensures table exists)