2.9.2-rc1
[phpmyadmin/arisferyanto.git] / libraries / tbl_properties_table_info.inc.php
blobdad94d05a0d8b3883c463fcb7739eb8eef3146f8
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once './libraries/Table.class.php';
7 /**
8 * extracts table properties from create statement
10 * @TODO this should be recoded as functions,
11 * to avoid messing with global variables
14 /**
15 * requirements
17 require_once('./libraries/common.lib.php');
19 // Check parameters
20 PMA_checkParameters(array('db', 'table'));
22 /**
23 * Defining global variables, in case this script is included by a function.
24 * This is necessary because this script can be included by libraries/header.inc.php.
26 global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
27 $table_info_num_rows, $auto_increment;
29 /**
30 * Gets table informations
32 // Seems we need to do this in MySQL 5.0.2,
33 // otherwise error #1046, no database selected
34 PMA_DBI_select_db($GLOBALS['db']);
36 // The 'show table' statement works correct since 3.23.03
37 $table_info_result = PMA_DBI_query(
38 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
39 null, PMA_DBI_QUERY_STORE);
41 // need this test because when we are creating a table, we get 0 rows
42 // from the SHOW TABLE query
43 // and we don't want to mess up the $tbl_type coming from the form
45 if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
46 $showtable = PMA_DBI_fetch_assoc($table_info_result);
47 PMA_DBI_free_result($table_info_result);
48 unset( $table_info_result );
50 if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
51 $showtable['Type'] =& $showtable['Engine'];
53 // MySQL < 5.0.13 returns "view", >= 5.0.13 returns "VIEW"
54 if ( PMA_MYSQL_INT_VERSION >= 50000 && !isset($showtable['Type'])
55 && isset($showtable['Comment'])
56 && strtoupper($showtable['Comment']) == 'VIEW' ) {
57 $tbl_is_view = true;
58 $tbl_type = $GLOBALS['strView'];
59 $show_comment = null;
60 } else {
61 $tbl_is_view = false;
62 $tbl_type = isset($showtable['Type'])
63 ? strtoupper($showtable['Type'])
64 : '';
65 // a new comment could be coming from tbl_properties_operations.php
66 // and we want to show it in the header
67 if (isset($submitcomment) && isset($comment)) {
68 $show_comment = $comment;
69 } else {
70 $show_comment = isset($showtable['Comment'])
71 ? $showtable['Comment']
72 : '';
75 $tbl_collation = empty($showtable['Collation'])
76 ? ''
77 : $showtable['Collation'];
79 if ( null === $showtable['Rows'] ) {
80 $showtable['Rows'] = PMA_Table::countRecords( $GLOBALS['db'],
81 $showtable['Name'], true, true );
83 $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
84 $auto_increment = isset($showtable['Auto_increment'])
85 ? $showtable['Auto_increment']
86 : '';
88 $create_options = isset($showtable['Create_options'])
89 ? explode(' ', $showtable['Create_options'])
90 : array();
92 // export create options by its name as variables into gloabel namespace
93 // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
94 unset($pack_keys);
95 foreach ( $create_options as $each_create_option ) {
96 $each_create_option = explode('=', $each_create_option);
97 if ( isset( $each_create_option[1] ) ) {
98 $$each_create_option[0] = $each_create_option[1];
101 // we need explicit DEFAULT value here (different from '0')
102 $pack_keys = (!isset($pack_keys) || strlen($pack_keys) == 0) ? 'DEFAULT' : $pack_keys;
103 unset( $create_options, $each_create_option );
104 } // end if