Translated using Weblate (Indonesian)
[phpmyadmin.git] / libraries / db_info.inc.php
blob569cb4a16f75ea95916b16821304e96c3427788b
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 * speedup view on locked tables
12 * @package PhpMyAdmin
14 if (! defined('PHPMYADMIN')) {
15 exit;
18 /**
19 * limits for table list
21 if (! isset($_SESSION['tmp_user_values']['table_limit_offset'])
22 || $_SESSION['tmp_user_values']['table_limit_offset_db'] != $db
23 ) {
24 $_SESSION['tmp_user_values']['table_limit_offset'] = 0;
25 $_SESSION['tmp_user_values']['table_limit_offset_db'] = $db;
27 if (isset($_REQUEST['pos'])) {
28 $_SESSION['tmp_user_values']['table_limit_offset'] = (int) $_REQUEST['pos'];
30 $pos = $_SESSION['tmp_user_values']['table_limit_offset'];
32 PMA_Util::checkParameters(array('db'));
34 /**
35 * @global bool whether to display extended stats
37 $is_show_stats = $cfg['ShowStats'];
39 /**
40 * @global bool whether selected db is information_schema
42 $db_is_information_schema = false;
44 if (PMA_is_system_schema($db)) {
45 $is_show_stats = false;
46 $db_is_information_schema = true;
49 /**
50 * @global array information about tables in db
52 $tables = array();
54 // When used in Nested table group mode,
55 // only show tables matching the given groupname
56 if (PMA_isValid($tbl_group)) {
57 $tbl_group_sql = ' LIKE "'
58 . PMA_Util::escapeMysqlWildcards($tbl_group)
59 . '%"';
60 } else {
61 $tbl_group_sql = '';
64 $tooltip_truename = array();
65 $tooltip_aliasname = array();
67 // Special speedup for newer MySQL Versions (in 4.0 format changed)
68 if (true === $cfg['SkipLockedTables']) {
69 $db_info_result = PMA_DBI_query(
70 'SHOW OPEN TABLES FROM ' . PMA_Util::backquote($db) . ';'
73 // Blending out tables in use
74 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
75 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
76 // if in use memorize tablename
77 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
78 $sot_cache[$tmp[0]] = true;
81 PMA_DBI_free_result($db_info_result);
83 if (isset($sot_cache)) {
84 $db_info_result = PMA_DBI_query(
85 'SHOW TABLES FROM ' . PMA_Util::backquote($db) . $tbl_group_sql . ';',
86 null, PMA_DBI_QUERY_STORE
88 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
89 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
90 if (! isset($sot_cache[$tmp[0]])) {
91 $sts_result = PMA_DBI_query(
92 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db)
93 . ' LIKE \'' . PMA_Util::sqlAddSlashes($tmp[0], true) . '\';'
95 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
96 PMA_DBI_free_result($sts_result);
97 unset($sts_result);
99 if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
100 $sts_tmp['Type'] =& $sts_tmp['Engine'];
103 if (! empty($tbl_group)
104 && ! preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])
106 continue;
109 if ($cfg['ShowTooltip']) {
110 PMA_Util::fillTooltip(
111 $tooltip_truename, $tooltip_aliasname, $sts_tmp
115 $tables[$sts_tmp['Name']] = $sts_tmp;
116 } else { // table in use
117 $tables[$tmp[0]] = array('Name' => $tmp[0]);
120 if ($GLOBALS['cfg']['NaturalOrder']) {
121 uksort($tables, 'strnatcasecmp');
124 $sot_ready = true;
125 } elseif ($db_info_result) {
126 PMA_DBI_free_result($db_info_result);
128 unset($sot_cache);
130 unset($tmp);
131 } elseif ($db_info_result) {
132 PMA_DBI_free_result($db_info_result);
136 if (! isset($sot_ready)) {
138 // Set some sorting defaults
139 $sort = 'Name';
140 $sort_order = 'ASC';
142 if (isset($_REQUEST['sort'])) {
143 $sortable_name_mappings = array(
144 'table' => 'Name',
145 'records' => 'Rows',
146 'type' => 'Engine',
147 'collation' => 'Collation',
148 'size' => 'Data_length',
149 'overhead' => 'Data_free',
150 'creation' => 'Create_time',
151 'last_update' => 'Update_time',
152 'last_check' => 'Check_time'
155 // Make sure the sort type is implemented
156 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
157 $sort = $sortable_name_mappings[$_REQUEST['sort']];
158 if ($_REQUEST['sort_order'] == 'DESC') {
159 $sort_order = 'DESC';
164 if (! empty($tbl_group)) {
165 // only tables for selected group
166 $tables = PMA_DBI_get_tables_full(
167 $db, $tbl_group, true, null, 0, false, $sort, $sort_order
169 } else {
170 // all tables in db
171 // - get the total number of tables
172 // (needed for proper working of the MaxTableList feature)
173 $tables = PMA_DBI_get_tables($db);
174 $total_num_tables = count($tables);
175 if (isset($sub_part) && $sub_part == '_export') {
176 // (don't fetch only a subset if we are coming from db_export.php,
177 // because I think it's too risky to display only a subset of the
178 // table names when exporting a db)
181 * @todo Page selector for table names?
183 $tables = PMA_DBI_get_tables_full(
184 $db, false, false, null, 0, false, $sort, $sort_order
186 } else {
187 // fetch the details for a possible limited subset
188 $tables = PMA_DBI_get_tables_full(
189 $db, false, false, null, $pos, true, $sort, $sort_order
194 if ($cfg['ShowTooltip']) {
195 foreach ($tables as $each_table) {
196 PMA_Util::fillTooltip(
197 $tooltip_truename, $tooltip_aliasname, $each_table
204 * @global int count of tables in db
206 $num_tables = count($tables);
207 // (needed for proper working of the MaxTableList feature)
208 if (! isset($total_num_tables)) {
209 $total_num_tables = $num_tables;
213 * cleanup
215 unset($each_table, $tbl_group_sql, $db_info_result);
218 * If coming from a Show MySQL link on the home page,
219 * put something in $sub_part
221 if (empty($sub_part)) {
222 $sub_part = '_structure';