Another Acknowledgements page update (fix for previous commit)
[openemr.git] / phpmyadmin / libraries / db_table_exists.lib.php
blob0f8e60d5931586571f98c7cb2565f3d1b4e5b2fe
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 * @version $Id$
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
16 if (empty($is_db)) {
17 if (strlen($db)) {
18 $is_db = @PMA_DBI_select_db($db);
19 } else {
20 $is_db = false;
23 if (! $is_db) {
24 // not a valid db name -> back to the welcome page
25 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
26 $url_params = array('reload' => 1);
27 if (isset($message)) {
28 $url_params['message'] = $message;
30 if (! empty($sql_query)) {
31 $url_params['sql_query'] = $sql_query;
33 if (isset($show_as_php)) {
34 $url_params['show_as_php'] = $show_as_php;
36 PMA_sendHeaderLocation(
37 $cfg['PmaAbsoluteUri'] . 'main.php'
38 . PMA_generate_common_url($url_params, '&'));
40 exit;
42 } // end if (ensures db exists)
44 if (empty($is_table) && !defined('PMA_SUBMIT_MULT')) {
45 // Not a valid table name -> back to the db_sql.php
46 if (strlen($table)) {
47 $_result = PMA_DBI_try_query(
48 'SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, true) . '\';',
49 null, PMA_DBI_QUERY_STORE);
50 $is_table = @PMA_DBI_num_rows($_result);
51 PMA_DBI_free_result($_result);
52 } else {
53 $is_table = false;
56 if (! $is_table) {
57 if (! defined('IS_TRANSFORMATION_WRAPPER')) {
58 if (strlen($table)) {
59 // SHOW TABLES doesn't show temporary tables, so try select
60 // (as it can happen just in case temporary table, it should be
61 // fast):
63 /**
64 * @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER?
66 $_result = PMA_DBI_try_query(
67 'SELECT COUNT(*) FROM ' . PMA_backquote($table) . ';',
68 null, PMA_DBI_QUERY_STORE);
69 $is_table = ($_result && @PMA_DBI_num_rows($_result));
70 PMA_DBI_free_result($_result);
73 if (! $is_table) {
74 $url_params = array('reload' => 1, 'db' => $db);
75 if (isset($message)) {
76 $url_params['message'] = $message;
78 if (! empty($sql_query)) {
79 $url_params['sql_query'] = $sql_query;
81 if (isset($display_query)) {
82 $url_params['display_query'] = $display_query;
84 PMA_sendHeaderLocation(
85 $cfg['PmaAbsoluteUri'] . 'db_sql.php'
86 . PMA_generate_common_url($url_params, '&'));
90 if (! $is_table) {
91 exit;
94 } // end if (ensures table exists)