Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / db_table_exists.lib.php
blobef8b927d5fa5bc2027ac94995d41f5b472e97b66
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 = @PMA_DBI_select_db($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 = PMA_DBI_try_query(
62 'SHOW TABLES LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\';',
63 null, PMA_DBI_QUERY_STORE
65 $is_table = @PMA_DBI_num_rows($_result);
66 PMA_DBI_free_result($_result);
68 } else {
69 $is_table = false;
72 if (! $is_table) {
73 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
74 if (strlen($table)) {
75 // SHOW TABLES doesn't show temporary tables, so try select
76 // (as it can happen just in case temporary table, it should be
77 // fast):
79 /**
80 * @todo should this check really
81 * only happen if IS_TRANSFORMATION_WRAPPER?
83 $_result = PMA_DBI_try_query(
84 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($table) . ';',
85 null,
86 PMA_DBI_QUERY_STORE
88 $is_table = ($_result && @PMA_DBI_num_rows($_result));
89 PMA_DBI_free_result($_result);
92 if (! $is_table) {
93 include './db_sql.php';
94 exit;
98 if (! $is_table) {
99 exit;
102 } // end if (ensures table exists)