db_table_exists.lib.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 = @$GLOBALS['dbi']->selectDb($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_URL_getCommon($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 = $GLOBALS['dbi']->tryQuery(
  57. 'SHOW TABLES LIKE \'' . PMA_Util::sqlAddSlashes($table, true)
  58. . '\';',
  59. null, PMA_DatabaseInterface::QUERY_STORE
  60. );
  61. $is_table = @$GLOBALS['dbi']->numRows($_result);
  62. $GLOBALS['dbi']->freeResult($_result);
  63. }
  64. } else {
  65. $is_table = false;
  66. }
  67. if (! $is_table) {
  68. if (! defined('IS_TRANSFORMATION_WRAPPER')) {
  69. if (strlen($table)) {
  70. // SHOW TABLES doesn't show temporary tables, so try select
  71. // (as it can happen just in case temporary table, it should be
  72. // fast):
  73. /**
  74. * @todo should this check really
  75. * only happen if IS_TRANSFORMATION_WRAPPER?
  76. */
  77. $_result = $GLOBALS['dbi']->tryQuery(
  78. 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($table) . ';',
  79. null,
  80. PMA_DatabaseInterface::QUERY_STORE
  81. );
  82. $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result));
  83. $GLOBALS['dbi']->freeResult($_result);
  84. }
  85. if (! $is_table) {
  86. include './db_sql.php';
  87. exit;
  88. }
  89. }
  90. if (! $is_table) {
  91. exit;
  92. }
  93. }
  94. } // end if (ensures table exists)
  95. ?>