-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathdescTable.php
60 lines (46 loc) · 1.92 KB
/
descTable.php
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
<?php
require_once('init.php');
$return = array();
$label = $_REQUEST['label'];
$database = $_REQUEST['db'];
$table = $_REQUEST['table'];
$return['label'] = $label;
$return['database'] = $database;
$return['table'] = $table;
$return['column'] = $col;
$return['title'] = "{$database}.${table}";
$host = $explainhosts[$label];
Database::connect(null, $host['user'], $host['password'], null, null, 'pdo', array('dsn' => $host['dsn']), $label);
Database::find($label)->query('USE '.Database::escapeField($database));
list($tmp, $return['create']) = Database::find($label)->query_row('SHOW CREATE TABLE '.Database::escapeField($table));
$return['create'] = SqlParser::html($return['create']);
$desc = Database::find($label)->query_list_assoc('DESC '.Database::escapeField($table));
$return['desc'] = '<table><thead><tr>';
foreach (array_keys($desc[0]) as $key)
$return['desc'] .= '<th>'.$key.'</th>';
$return['desc'] .= '</tr></thead><tbody>';
foreach ($desc as $row) {
$return['desc'] .= '<tr>';
foreach ($row as $key => $val)
$return['desc'] .= '<td>'.ifnull($val, 'NULL').'</td>';
$return['desc'] .= '</tr>';
}
$return['desc'] .= '</tbody></table>';
unset($desc);
$indexes = Database::find($label)->query_list_assoc('SHOW INDEXES FROM '.Database::escapeField($table));
$return['indexes'] = '<table><thead><tr>';
foreach (array_keys($indexes[0]) as $key)
$return['indexes'] .= '<th>'.$key.'</th>';
$return['indexes'] .= '</tr></thead><tbody>';
foreach ($indexes as $row) {
$return['indexes'] .= '<tr>';
foreach ($row as $key => $val)
$return['indexes'] .= '<td>'.ifnull($val, 'NULL').'</td>';
$return['indexes'] .= '</tr>';
}
$return['indexes'] .= '</tbody></table>';
unset($indexes);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($return);