Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / db_info.inc.php
blobc3d66b7b07a6e1e88bc156bf109f64b71febd14b
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['tmpval']['table_limit_offset'])
22 || $_SESSION['tmpval']['table_limit_offset_db'] != $db
23 ) {
24 $_SESSION['tmpval']['table_limit_offset'] = 0;
25 $_SESSION['tmpval']['table_limit_offset_db'] = $db;
27 if (isset($_REQUEST['pos'])) {
28 $_SESSION['tmpval']['table_limit_offset'] = (int) $_REQUEST['pos'];
30 $pos = $_SESSION['tmpval']['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 ($GLOBALS['dbi']->isSystemSchema($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 $tooltip_truename = array();
55 $tooltip_aliasname = array();
57 // Special speedup for newer MySQL Versions (in 4.0 format changed)
58 if (true === $cfg['SkipLockedTables'] && ! PMA_DRIZZLE) {
59 $db_info_result = $GLOBALS['dbi']->query(
60 'SHOW OPEN TABLES FROM ' . PMA_Util::backquote($db) . ';'
63 // Blending out tables in use
64 if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
65 while ($tmp = $GLOBALS['dbi']->fetchAssoc($db_info_result)) {
66 // if in use, memorize table name
67 if ($tmp['In_use'] > 0) {
68 $sot_cache[$tmp['Table']] = true;
71 $GLOBALS['dbi']->freeResult($db_info_result);
73 if (isset($sot_cache)) {
74 $db_info_result = false;
76 $tblGroupSql = "";
77 $whereAdded = false;
78 if (PMA_isValid($_REQUEST['tbl_group'])) {
79 $tblGroupSql .= " WHERE "
80 . PMA_Util::backquote('Tables_in_' . $db)
81 . " LIKE '"
82 . PMA_Util::escapeMysqlWildcards($_REQUEST['tbl_group'])
83 . "%'";
84 $whereAdded = true;
86 if (PMA_isValid($_REQUEST['tbl_type'], array('table', 'view'))) {
87 $tblGroupSql .= $whereAdded ? " AND" : " WHERE";
88 if ($_REQUEST['tbl_type'] == 'view') {
89 $tblGroupSql .= " `Table_type` != 'BASE TABLE'";
90 } else {
91 $tblGroupSql .= " `Table_type` = 'BASE TABLE'";
94 $db_info_result = $GLOBALS['dbi']->query(
95 'SHOW FULL TABLES FROM ' . PMA_Util::backquote($db) . $tblGroupSql,
96 null, PMA_DatabaseInterface::QUERY_STORE
98 unset($tblGroupSql, $whereAdded);
100 if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
101 while ($tmp = $GLOBALS['dbi']->fetchRow($db_info_result)) {
102 if (! isset($sot_cache[$tmp[0]])) {
103 $sts_result = $GLOBALS['dbi']->query(
104 "SHOW TABLE STATUS FROM " . PMA_Util::backquote($db)
105 . " LIKE '" . PMA_Util::sqlAddSlashes($tmp[0], true)
106 . "';"
108 $sts_tmp = $GLOBALS['dbi']->fetchAssoc($sts_result);
109 $GLOBALS['dbi']->freeResult($sts_result);
110 unset($sts_result);
112 if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
113 $sts_tmp['Type'] =& $sts_tmp['Engine'];
115 $tables[$sts_tmp['Name']] = $sts_tmp;
116 } else { // table in use
117 $tables[$tmp[0]] = array(
118 'TABLE_NAME' => $tmp[0],
119 'ENGINE' => '',
120 'TABLE_TYPE' => '',
121 'TABLE_ROWS' => 0,
125 if ($GLOBALS['cfg']['NaturalOrder']) {
126 uksort($tables, 'strnatcasecmp');
129 $sot_ready = true;
130 } elseif ($db_info_result) {
131 $GLOBALS['dbi']->freeResult($db_info_result);
133 unset($sot_cache);
135 unset($tmp);
136 } elseif ($db_info_result) {
137 $GLOBALS['dbi']->freeResult($db_info_result);
141 if (! isset($sot_ready)) {
143 // Set some sorting defaults
144 $sort = 'Name';
145 $sort_order = 'ASC';
147 if (isset($_REQUEST['sort'])) {
148 $sortable_name_mappings = array(
149 'table' => 'Name',
150 'records' => 'Rows',
151 'type' => 'Engine',
152 'collation' => 'Collation',
153 'size' => 'Data_length',
154 'overhead' => 'Data_free',
155 'creation' => 'Create_time',
156 'last_update' => 'Update_time',
157 'last_check' => 'Check_time'
160 // Make sure the sort type is implemented
161 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
162 $sort = $sortable_name_mappings[$_REQUEST['sort']];
163 if ($_REQUEST['sort_order'] == 'DESC') {
164 $sort_order = 'DESC';
169 $tbl_group = false;
170 $tbl_type = null;
171 $limit_offset = 0;
172 $limit_count = false;
174 if (! empty($_REQUEST['tbl_group']) || ! empty($_REQUEST['tbl_type'])) {
175 if (! empty($_REQUEST['tbl_group'])) {
176 // only tables for selected group
177 $tbl_group = $_REQUEST['tbl_group'];
179 if (! empty($_REQUEST['tbl_type'])) {
180 // only tables for selected type
181 $tbl_type = $_REQUEST['tbl_type'];
183 } else {
184 // all tables in db
185 // - get the total number of tables
186 // (needed for proper working of the MaxTableList feature)
187 $tables = $GLOBALS['dbi']->getTables($db);
188 $total_num_tables = count($tables);
189 if (isset($sub_part) && $sub_part == '_export') {
190 // (don't fetch only a subset if we are coming from db_export.php,
191 // because I think it's too risky to display only a subset of the
192 // table names when exporting a db)
195 * @todo Page selector for table names?
197 } else {
198 // fetch the details for a possible limited subset
199 $limit_offset = $pos;
200 $limit_count = true;
203 $tables = $GLOBALS['dbi']->getTablesFull(
204 $db, $tbl_group, ($tbl_group != false), null, $limit_offset,
205 $limit_count, $sort, $sort_order, $tbl_type
210 * @global int count of tables in db
212 $num_tables = count($tables);
213 // (needed for proper working of the MaxTableList feature)
214 if (! isset($total_num_tables)) {
215 $total_num_tables = $num_tables;
219 * cleanup
221 unset($each_table, $db_info_result);
224 * If coming from a Show MySQL link on the home page,
225 * put something in $sub_part
227 if (empty($sub_part)) {
228 $sub_part = '_structure';