bug #2063100 Unknown column Event_priv
[phpmyadmin/crack.git] / libraries / db_info.inc.php
blob8ae3b71471940e6d150576ebeb7e4100d45d0e73
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Gets the list of the table in the current db and informations about these
5 * tables if possible
7 * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
8 * and $db_is_information_schema
10 * staybyte: speedup view on locked tables - 11 June 2001
12 * @uses $cfg['ShowStats']
13 * @uses $cfg['ShowTooltip']
14 * @uses $cfg['ShowTooltipAliasTB']
15 * @uses $cfg['SkipLockedTables']
16 * @uses $GLOBALS['db']
17 * @uses PMA_fillTooltip()
18 * @uses PMA_checkParameters()
19 * @uses PMA_escape_mysql_wildcards()
20 * @uses PMA_DBI_query()
21 * @uses PMA_backquote()
22 * @uses PMA_DBI_num_rows()
23 * @uses PMA_DBI_fetch_row()
24 * @uses PMA_DBI_fetch_assoc()
25 * @uses PMA_DBI_free_result()
26 * @uses PMA_DBI_get_tables_full()
27 * @uses PMA_isValid()
28 * @uses preg_match()
29 * @uses preg_quote()
30 * @uses uksort()
31 * @uses strnatcasecmp()
32 * @uses count()
33 * @uses addslashes()
34 * @version $Id$
36 if (! defined('PHPMYADMIN')) {
37 exit;
40 /**
41 * requirements
43 require_once './libraries/common.inc.php';
45 /**
46 * limits for table list
48 if (! isset($_SESSION['userconf']['table_limit_offset'])) {
49 $_SESSION['userconf']['table_limit_offset'] = 0;
51 if (isset($_REQUEST['pos'])) {
52 $_SESSION['userconf']['table_limit_offset'] = (int) $_REQUEST['pos'];
54 $pos = $_SESSION['userconf']['table_limit_offset'];
56 /**
57 * fills given tooltip arrays
59 * @uses $cfg['ShowTooltipAliasTB']
60 * @uses $GLOBALS['strStatCreateTime']
61 * @uses PMA_localisedDate()
62 * @uses strtotime()
63 * @param array $tooltip_truename tooltip data
64 * @param array $tooltip_aliasname tooltip data
65 * @param array $table tabledata
67 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
69 if (empty($table['Comment'])) {
70 $table['Comment'] = $table['Name'];
71 } else {
72 // why?
73 $table['Comment'] .= ' ';
76 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
77 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
78 $tooltip_truename[$table['Name']] = $table['Comment'];
79 $tooltip_aliasname[$table['Name']] = $table['Name'];
80 } else {
81 $tooltip_truename[$table['Name']] = $table['Name'];
82 $tooltip_aliasname[$table['Name']] = $table['Comment'];
85 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
86 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
87 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
90 if (! empty($table['Update_time'])) {
91 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
92 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
95 if (! empty($table['Check_time'])) {
96 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
97 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
101 PMA_checkParameters(array('db'));
104 * @global bool whether to display extended stats
106 $is_show_stats = $cfg['ShowStats'];
109 * @global bool whether selected db is information_schema
111 $db_is_information_schema = false;
113 if ($db == 'information_schema') {
114 $is_show_stats = false;
115 $db_is_information_schema = true;
119 * @global array information about tables in db
121 $tables = array();
123 // When used in Nested table group mode, only show tables matching the given groupname
124 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
125 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
126 } else {
127 $tbl_group_sql = '';
130 if ($cfg['ShowTooltip']) {
131 $tooltip_truename = array();
132 $tooltip_aliasname = array();
135 // Special speedup for newer MySQL Versions (in 4.0 format changed)
136 if (true === $cfg['SkipLockedTables']) {
137 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
139 // Blending out tables in use
140 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
141 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
142 // if in use memorize tablename
143 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
144 $sot_cache[$tmp[0]] = true;
147 PMA_DBI_free_result($db_info_result);
149 if (isset($sot_cache)) {
150 $db_info_result = PMA_DBI_query(
151 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
152 null, PMA_DBI_QUERY_STORE);
153 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
154 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
155 if (!isset($sot_cache[$tmp[0]])) {
156 $sts_result = PMA_DBI_query(
157 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
158 . ' LIKE \'' . addslashes($tmp[0]) . '\';');
159 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
160 PMA_DBI_free_result($sts_result);
161 unset($sts_result);
163 if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
164 $sts_tmp['Type'] =& $sts_tmp['Engine'];
167 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
168 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
169 continue;
172 if ($cfg['ShowTooltip']) {
173 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
176 $tables[$sts_tmp['Name']] = $sts_tmp;
177 } else { // table in use
178 $tables[$tmp[0]] = array('Name' => $tmp[0]);
181 if ($GLOBALS['cfg']['NaturalOrder']) {
182 uksort($tables, 'strnatcasecmp');
185 $sot_ready = true;
186 } elseif ($db_info_result) {
187 PMA_DBI_free_result($db_info_result);
189 unset($sot_cache);
191 unset($tmp);
192 } elseif ($db_info_result) {
193 PMA_DBI_free_result($db_info_result);
197 if (! isset($sot_ready)) {
198 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
199 // only tables for selected group
200 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
201 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
202 // only tables for selected group,
203 // but grouping is done on comment ...
204 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
205 } else {
206 // all tables in db
207 // - get the total number of tables
208 // (needed for proper working of the MaxTableList feature)
209 $tables = PMA_DBI_get_tables($db);
210 $total_num_tables = count($tables);
211 if (isset($sub_part) && $sub_part == '_export') {
212 // (don't fetch only a subset if we are coming from db_export.php,
213 // because I think it's too risky to display only a subset of the
214 // table names when exporting a db)
217 * @todo Page selector for table names?
219 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false);
220 } else {
221 // fetch the details for a possible limited subset
222 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true);
226 if ($cfg['ShowTooltip']) {
227 foreach ($tables as $each_table) {
228 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
234 * @global int count of tables in db
236 $num_tables = count($tables);
237 // (needed for proper working of the MaxTableList feature)
238 if (! isset($total_num_tables)) {
239 $total_num_tables = $num_tables;
243 * cleanup
245 unset($each_table, $tbl_group_sql, $db_info_result);
248 * Displays top menu links
250 require './libraries/db_links.inc.php';