Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / tbl_info.inc.php
blobc1ed2cd75e6d3def703416b68db727c63dc44047
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * extracts table properties from create statement
6 * @todo should be handled by class Table
7 * @todo this should be recoded as functions, to avoid messing with global variables
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 // Check parameters
16 PMA_Util::checkParameters(array('db', 'table'));
18 /**
19 * Defining global variables, in case this script is included by a function.
21 global $showtable, $tbl_is_view, $tbl_storage_engine, $show_comment, $tbl_collation,
22 $table_info_num_rows, $auto_increment;
24 /**
25 * Gets table informations
27 // Seems we need to do this in MySQL 5.0.2,
28 // otherwise error #1046, no database selected
29 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
32 /**
33 * Holds information about the current table
35 * @todo replace this by PMA_Table
36 * @global array $GLOBALS['showtable']
37 * @name $showtable
39 $GLOBALS['showtable'] = array();
41 // PMA_Table::sGetStatusInfo() does caching by default, but here
42 // we force reading of the current table status
43 // if $reread_info is true (for example, coming from tbl_operations.php
44 // and we just changed the table's storage engine)
45 $GLOBALS['showtable'] = PMA_Table::sGetStatusInfo(
46 $GLOBALS['db'],
47 $GLOBALS['table'],
48 null,
49 (isset($reread_info) && $reread_info ? true : false)
52 // need this test because when we are creating a table, we get 0 rows
53 // from the SHOW TABLE query
54 // and we don't want to mess up the $tbl_storage_engine coming from the form
56 if ($showtable) {
57 if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
58 $tbl_is_view = true;
59 $tbl_storage_engine = __('View');
60 $show_comment = null;
61 } else {
62 $tbl_is_view = false;
63 $tbl_storage_engine = isset($showtable['Engine'])
64 ? strtoupper($showtable['Engine'])
65 : '';
66 $show_comment = '';
67 if (isset($showtable['Comment'])) {
68 $show_comment = $showtable['Comment'];
71 $tbl_collation = empty($showtable['Collation'])
72 ? ''
73 : $showtable['Collation'];
75 if (null === $showtable['Rows']) {
76 $showtable['Rows'] = PMA_Table::countRecords(
77 $GLOBALS['db'], $showtable['Name'], true
80 $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
81 $row_format = isset($showtable['Row_format']) ? $showtable['Row_format'] : '';
82 $auto_increment = isset($showtable['Auto_increment'])
83 ? $showtable['Auto_increment']
84 : '';
86 $create_options = isset($showtable['Create_options'])
87 ? explode(' ', $showtable['Create_options'])
88 : array();
90 // export create options by its name as variables into global namespace
91 // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
92 unset($pack_keys);
93 foreach ($create_options as $each_create_option) {
94 $each_create_option = explode('=', $each_create_option);
95 if (isset($each_create_option[1])) {
96 $$each_create_option[0] = $each_create_option[1];
99 // we need explicit DEFAULT value here (different from '0')
100 $pack_keys = (! isset($pack_keys) || strlen($pack_keys) == 0)
101 ? 'DEFAULT'
102 : $pack_keys;
103 unset($create_options, $each_create_option);
104 } // end if