Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / tbl_info.inc.php
blobdc8a325b8c4a69329bdee0284e7708fa508f0173
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
12 if (! defined('PHPMYADMIN')) {
13 exit;
16 // Check parameters
17 PMA\libraries\Util::checkParameters(array('db', 'table'));
19 /**
20 * Defining global variables, in case this script is included by a function.
22 global $showtable, $tbl_is_view, $tbl_storage_engine, $show_comment, $tbl_collation,
23 $table_info_num_rows, $auto_increment;
25 /**
26 * Gets table information
28 // Seems we need to do this in MySQL 5.0.2,
29 // otherwise error #1046, no database selected
30 $GLOBALS['dbi']->selectDb($GLOBALS['db']);
33 /**
34 * Holds information about the current table
36 * Table::getStatusInfo() does caching by default, but here
37 * we force reading of the current table status
38 * if $reread_info is true (for example, coming from tbl_operations.php
39 * and we just changed the table's storage engine)
41 * @todo replace this by Table
42 * @global array $GLOBALS['showtable']
43 * @name $showtable
45 $GLOBALS['showtable'] = $GLOBALS['dbi']->getTable(
46 $GLOBALS['db'],
47 $GLOBALS['table']
48 )->getStatusInfo(
49 null,
50 (isset($reread_info) && $reread_info ? true : false)
53 // need this test because when we are creating a table, we get 0 rows
54 // from the SHOW TABLE query
55 // and we don't want to mess up the $tbl_storage_engine coming from the form
57 if ($showtable) {
58 if ($GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])->isView()) {
59 $tbl_is_view = true;
60 $tbl_storage_engine = __('View');
61 $show_comment = null;
62 } else {
63 $tbl_is_view = false;
64 $tbl_storage_engine = isset($showtable['Engine'])
65 ? mb_strtoupper($showtable['Engine'])
66 : '';
67 $show_comment = '';
68 if (isset($showtable['Comment'])) {
69 $show_comment = $showtable['Comment'];
72 $tbl_collation = empty($showtable['Collation'])
73 ? ''
74 : $showtable['Collation'];
76 if (null === $showtable['Rows']) {
77 $showtable['Rows'] = $GLOBALS['dbi']
78 ->getTable($GLOBALS['db'], $showtable['Name'])
79 ->countRecords(true);
81 $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
82 $row_format = isset($showtable['Row_format']) ? $showtable['Row_format'] : '';
83 $auto_increment = isset($showtable['Auto_increment'])
84 ? $showtable['Auto_increment']
85 : '';
87 $create_options_tmp = isset($showtable['Create_options'])
88 ? explode(' ', $showtable['Create_options'])
89 : array();
90 $create_options = array();
92 // export create options by its name as variables into global namespace
93 // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
94 unset($pack_keys);
95 foreach ($create_options_tmp as $each_create_option) {
96 $each_create_option = explode('=', $each_create_option);
97 if (isset($each_create_option[1])) {
98 // ensure there is no ambiguity for PHP 5 and 7
99 $create_options[$each_create_option[0]] = $each_create_option[1];
102 // we need explicit DEFAULT value here (different from '0')
103 $create_options['pack_keys'] = (! isset($create_options['pack_keys']) || strlen($create_options['pack_keys']) == 0)
104 ? 'DEFAULT'
105 : $create_options['pack_keys'];
106 unset($create_options_tmp, $each_create_option);
107 } else {
108 $pack_keys = $row_format = null;
109 }// end if