home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / db_table_exists.lib.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  3.0 KB  |  96 lines

  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
  6.  *
  7.  * @version $Id: db_table_exists.lib.php 11326 2008-06-17 21:32:48Z lem9 $
  8.  */
  9. if (! defined('PHPMYADMIN')) {
  10.     exit;
  11. }
  12.  
  13. /**
  14.  *
  15.  */
  16. if (empty($is_db)) {
  17.     if (strlen($db)) {
  18.         $is_db = @PMA_DBI_select_db($db);
  19.     } else {
  20.         $is_db = false;
  21.     }
  22.  
  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;
  29.             }
  30.             if (! empty($sql_query)) {
  31.                 $url_params['sql_query'] = $sql_query;
  32.             }
  33.             if (isset($show_as_php)) {
  34.                 $url_params['show_as_php'] = $show_as_php;
  35.             }
  36.             PMA_sendHeaderLocation(
  37.                 $cfg['PmaAbsoluteUri'] . 'main.php'
  38.                     . PMA_generate_common_url($url_params, '&'));
  39.         }
  40.         exit;
  41.     }
  42. } // end if (ensures db exists)
  43.  
  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;
  54.     }
  55.  
  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):
  62.  
  63.                 /**
  64.                  * @todo should this check really only happen if IS_TRANSFORMATION_WRAPPER?
  65.                  */
  66.                 $_result = PMA_DBI_try_query(
  67.                     'SELECT COUNT(*) FROM `' . PMA_sqlAddslashes($table, true) . '`;',
  68.                     null, PMA_DBI_QUERY_STORE);
  69.                 $is_table = ($_result && @PMA_DBI_num_rows($_result));
  70.                 PMA_DBI_free_result($_result);
  71.             }
  72.  
  73.             if (! $is_table) {
  74.                 $url_params = array('reload' => 1, 'db' => $db);
  75.                 if (isset($message)) {
  76.                     $url_params['message'] = $message;
  77.                 }
  78.                 if (! empty($sql_query)) {
  79.                     $url_params['sql_query'] = $sql_query;
  80.                 }
  81.                 if (isset($display_query)) {
  82.                     $url_params['display_query'] = $display_query;
  83.                 }
  84.                 PMA_sendHeaderLocation(
  85.                     $cfg['PmaAbsoluteUri'] . 'db_sql.php'
  86.                         . PMA_generate_common_url($url_params, '&'));
  87.             }
  88.         }
  89.  
  90.         if (! $is_table) {
  91.             exit;
  92.         }
  93.     }
  94. } // end if (ensures table exists)
  95. ?>
  96.