Merge branch 'QA_4_4' into QA_4_5
[phpmyadmin.git] / libraries / tbl_info.inc.php
blob1f70188e7bf6e0ead0fe37ae978e46b36b8e294c
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 information
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::getStatusInfo() 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'] = $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 /** @var PMA_String $pmaString */
59 $pmaString = $GLOBALS['PMA_String'];
61 if ($GLOBALS['dbi']->getTable($GLOBALS['db'], $GLOBALS['table'])->isView()) {
62 $tbl_is_view = true;
63 $tbl_storage_engine = __('View');
64 $show_comment = null;
65 } else {
66 $tbl_is_view = false;
67 $tbl_storage_engine = isset($showtable['Engine'])
68 ? /*overload*/mb_strtoupper($showtable['Engine'])
69 : '';
70 $show_comment = '';
71 if (isset($showtable['Comment'])) {
72 $show_comment = $showtable['Comment'];
75 $tbl_collation = empty($showtable['Collation'])
76 ? ''
77 : $showtable['Collation'];
79 if (null === $showtable['Rows']) {
80 $showtable['Rows'] = $GLOBALS['dbi']
81 ->getTable($GLOBALS['db'], $showtable['Name'])
82 ->countRecords(true);
84 $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
85 $row_format = isset($showtable['Row_format']) ? $showtable['Row_format'] : '';
86 $auto_increment = isset($showtable['Auto_increment'])
87 ? $showtable['Auto_increment']
88 : '';
90 $create_options = isset($showtable['Create_options'])
91 ? explode(' ', $showtable['Create_options'])
92 : array();
94 // export create options by its name as variables into global namespace
95 // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
96 unset($pack_keys);
97 foreach ($create_options as $each_create_option) {
98 $each_create_option = explode('=', $each_create_option);
99 if (isset($each_create_option[1])) {
100 // ensure there is no ambiguity for PHP 5 and 7
101 ${$each_create_option[0]} = $each_create_option[1];
104 // we need explicit DEFAULT value here (different from '0')
105 $pack_keys = (! isset($pack_keys) || /*overload*/mb_strlen($pack_keys) == 0)
106 ? 'DEFAULT'
107 : $pack_keys;
108 unset($create_options, $each_create_option);
109 } // end if