db_table_exists.lib.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * @package PhpMyAdmin
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. if (empty($is_db)) {
  13. if (strlen($db)) {
  14. $is_db = @PMA_DBI_select_db($db);
  15. } else {
  16. $is_db = false;
  17. }
  18. if (! $is_db) {
  19. // not a valid db name -> back to the welcome page
  20. if (! defined('IS_TRANSFORMATION_WRAPPER')) {
  21. $response = PMA_Response::getInstance();
  22. if ($response->isAjax()) {
  23. $response->isSuccess(false);
  24. $response->addJSON(
  25. 'message',
  26. PMA_Message::error(__('No databases selected.'))
  27. );
  28. } else {
  29. $url_params = array('reload' => 1);
  30. if (isset($message)) {
  31. $url_params['message'] = $message;
  32. }
  33. if (! empty($sql_query)) {
  34. $url_params['sql_query'] = $sql_query;
  35. }
  36. if (isset($show_as_php)) {
  37. $url_params['show_as_php'] = $show_as_php;
  38. }
  39. PMA_sendHeaderLocation(
  40. $cfg['PmaAbsoluteUri'] . 'index.php'
  41. . PMA_generate_common_url($url_params, '&')
  42. );
  43. }
  44. exit;
  45. }
  46. }
  47. } // end if (ensures db exists)
  48. if (empty($is_table)
  49. && !defined('PMA_SUBMIT_MULT')
  50. && ! defined('TABLE_MAY_BE_ABSENT')
  51. ) {
  52. // Not a valid table name -> back to the db_sql.php
  53. if (strlen($table)) {
  54. $is_table = isset(PMA_Table::$cache[$db][$table]);
  55. if (! $is_table) {
  56. $_result = PMA_DBI_try_query(
  57. 'SHOW TABLES LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\';',
  58. null, PMA_DBI_QUERY_STORE
  59. );
  60. $is_table = @PMA_DBI_num_rows($_result);
  61. PMA_DBI_free_result($_result);
  62. }
  63. } else {
  64. $is_table = false;
  65. }
  66. if (! $is_table) {
  67. if (! defined('IS_TRANSFORMATION_WRAPPER')) {
  68. if (strlen($table)) {
  69. // SHOW TABLES doesn't show temporary tables, so try select
  70. // (as it can happen just in case temporary table, it should be
  71. // fast):
  72. /**
  73. * @todo should this check really
  74. * only happen if IS_TRANSFORMATION_WRAPPER?
  75. */
  76. $_result = PMA_DBI_try_query(
  77. 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($table) . ';',
  78. null,
  79. PMA_DBI_QUERY_STORE
  80. );
  81. $is_table = ($_result && @PMA_DBI_num_rows($_result));
  82. PMA_DBI_free_result($_result);
  83. }
  84. if (! $is_table) {
  85. include './db_sql.php';
  86. exit;
  87. }
  88. }
  89. if (! $is_table) {
  90. exit;
  91. }
  92. }
  93. } // end if (ensures table exists)
  94. ?>