MultiTableQuery.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Handles DB Multi-table query
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Database;
  9. use PhpMyAdmin\DatabaseInterface;
  10. use PhpMyAdmin\ParseAnalyze;
  11. use PhpMyAdmin\Sql;
  12. use PhpMyAdmin\Template;
  13. /**
  14. * Class to handle database Multi-table querying
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. class MultiTableQuery
  19. {
  20. /**
  21. * DatabaseInterface instance
  22. *
  23. * @access private
  24. * @var DatabaseInterface
  25. */
  26. private $dbi;
  27. /**
  28. * Database name
  29. *
  30. * @access private
  31. * @var string
  32. */
  33. private $db;
  34. /**
  35. * Default number of columns
  36. *
  37. * @access private
  38. * @var integer
  39. */
  40. private $defaultNoOfColumns;
  41. /**
  42. * Table names
  43. *
  44. * @access private
  45. * @var array
  46. */
  47. private $tables;
  48. /**
  49. * Constructor
  50. *
  51. * @param DatabaseInterface $dbi DatabaseInterface instance
  52. * @param string $dbName Database name
  53. * @param integer $defaultNoOfColumns Default number of columns
  54. */
  55. public function __construct(
  56. DatabaseInterface $dbi,
  57. $dbName,
  58. $defaultNoOfColumns = 3
  59. ) {
  60. $this->dbi = $dbi;
  61. $this->db = $dbName;
  62. $this->defaultNoOfColumns = $defaultNoOfColumns;
  63. $this->tables = $this->dbi->getTables($this->db);
  64. }
  65. /**
  66. * Get Multi-Table query page HTML
  67. *
  68. * @return string Multi-Table query page HTML
  69. */
  70. public function getFormHtml()
  71. {
  72. $tables = [];
  73. foreach($this->tables as $table) {
  74. $tables[$table]['hash'] = md5($table);
  75. $tables[$table]['columns'] = array_keys(
  76. $this->dbi->getColumns($this->db, $table)
  77. );
  78. }
  79. return Template::get('database/multi_table_query/form')->render([
  80. 'db' => $this->db,
  81. 'tables' => $tables,
  82. 'default_no_of_columns' => $this->defaultNoOfColumns,
  83. ]);
  84. }
  85. /**
  86. * Displays multi-table query results
  87. *
  88. * @param string $sqlQuery The query to parse
  89. * @param string $db The current database
  90. * @param string $pmaThemeImage Uri of the PMA theme image
  91. *
  92. * @return void
  93. */
  94. public static function displayResults($sqlQuery, $db, $pmaThemeImage)
  95. {
  96. list(
  97. $analyzedSqlResults,
  98. $db,
  99. $tableFromSql
  100. ) = ParseAnalyze::sqlQuery($sqlQuery, $db);
  101. extract($analyzedSqlResults);
  102. $goto = 'db_multi_table_query.php';
  103. $sql = new Sql();
  104. $sql->executeQueryAndSendQueryResponse(
  105. null, // analyzed_sql_results
  106. false, // is_gotofile
  107. $db, // db
  108. null, // table
  109. null, // find_real_end
  110. null, // sql_query_for_bookmark - see below
  111. null, // extra_data
  112. null, // message_to_show
  113. null, // message
  114. null, // sql_data
  115. $goto, // goto
  116. $pmaThemeImage, // pmaThemeImage
  117. null, // disp_query
  118. null, // disp_message
  119. null, // query_type
  120. $sqlQuery, // sql_query
  121. null, // selectedTables
  122. null // complete_query
  123. );
  124. }
  125. }