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