Translated using Weblate (French)
[phpmyadmin.git] / libraries / db_info.inc.php
blob61df7e7b6db85e86e839f08ae68a139dfe721a8f
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 $tables[$sts_tmp['Name']] = $sts_tmp;
110 } else { // table in use
111 $tables[$tmp[0]] = array('Name' => $tmp[0]);
114 if ($GLOBALS['cfg']['NaturalOrder']) {
115 uksort($tables, 'strnatcasecmp');
118 $sot_ready = true;
119 } elseif ($db_info_result) {
120 PMA_DBI_free_result($db_info_result);
122 unset($sot_cache);
124 unset($tmp);
125 } elseif ($db_info_result) {
126 PMA_DBI_free_result($db_info_result);
130 if (! isset($sot_ready)) {
132 // Set some sorting defaults
133 $sort = 'Name';
134 $sort_order = 'ASC';
136 if (isset($_REQUEST['sort'])) {
137 $sortable_name_mappings = array(
138 'table' => 'Name',
139 'records' => 'Rows',
140 'type' => 'Engine',
141 'collation' => 'Collation',
142 'size' => 'Data_length',
143 'overhead' => 'Data_free',
144 'creation' => 'Create_time',
145 'last_update' => 'Update_time',
146 'last_check' => 'Check_time'
149 // Make sure the sort type is implemented
150 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
151 $sort = $sortable_name_mappings[$_REQUEST['sort']];
152 if ($_REQUEST['sort_order'] == 'DESC') {
153 $sort_order = 'DESC';
158 if (! empty($tbl_group)) {
159 // only tables for selected group
160 $tables = PMA_DBI_get_tables_full(
161 $db, $tbl_group, true, null, 0, false, $sort, $sort_order
163 } else {
164 // all tables in db
165 // - get the total number of tables
166 // (needed for proper working of the MaxTableList feature)
167 $tables = PMA_DBI_get_tables($db);
168 $total_num_tables = count($tables);
169 if (isset($sub_part) && $sub_part == '_export') {
170 // (don't fetch only a subset if we are coming from db_export.php,
171 // because I think it's too risky to display only a subset of the
172 // table names when exporting a db)
175 * @todo Page selector for table names?
177 $tables = PMA_DBI_get_tables_full(
178 $db, false, false, null, 0, false, $sort, $sort_order
180 } else {
181 // fetch the details for a possible limited subset
182 $tables = PMA_DBI_get_tables_full(
183 $db, false, false, null, $pos, true, $sort, $sort_order
190 * @global int count of tables in db
192 $num_tables = count($tables);
193 // (needed for proper working of the MaxTableList feature)
194 if (! isset($total_num_tables)) {
195 $total_num_tables = $num_tables;
199 * cleanup
201 unset($each_table, $tbl_group_sql, $db_info_result);
204 * If coming from a Show MySQL link on the home page,
205 * put something in $sub_part
207 if (empty($sub_part)) {
208 $sub_part = '_structure';