📄 tbl_structure.php
字号:
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * Displays table structure infos like fields/columns, indexes, size, rows * and allows manipulation of indexes and columns/fields * @version $Id: tbl_structure.php 12075 2008-12-03 21:49:03Z lem9 $ *//** * */require_once './libraries/common.inc.php';require_once './libraries/mysql_charsets.lib.php';require_once './libraries/relation.lib.php';$GLOBALS['js_include'][] = 'mootools.js';/** * handle multiple field commands if required * * submit_mult_*_x comes from IE if <input type="img" ...> is used */if (isset($_REQUEST['submit_mult_change_x'])) { $submit_mult = $strChange;} elseif (isset($_REQUEST['submit_mult_drop_x'])) { $submit_mult = $strDrop;} elseif (isset($_REQUEST['submit_mult_primary_x'])) { $submit_mult = $strPrimary;} elseif (isset($_REQUEST['submit_mult_index_x'])) { $submit_mult = $strIndex;} elseif (isset($_REQUEST['submit_mult_unique_x'])) { $submit_mult = $strUnique;} elseif (isset($_REQUEST['submit_mult_fulltext_x'])) { $submit_mult = $strIdxFulltext;} elseif (isset($_REQUEST['submit_mult_browse_x'])) { $submit_mult = $strBrowse;} elseif (isset($_REQUEST['submit_mult'])) { $submit_mult = $_REQUEST['submit_mult'];} elseif (isset($_REQUEST['mult_btn']) && $_REQUEST['mult_btn'] == $strYes) { $submit_mult = 'row_delete'; if (isset($_REQUEST['selected'])) { $_REQUEST['selected_fld'] = $_REQUEST['selected']; }}if (! empty($submit_mult) && isset($_REQUEST['selected_fld'])) { $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table); if ($submit_mult == $strBrowse) { // browsing the table displaying only selected fields/columns $GLOBALS['active_page'] = 'sql.php'; $sql_query = ''; foreach ($_REQUEST['selected_fld'] as $idx => $sval) { if ($sql_query == '') { $sql_query .= 'SELECT ' . PMA_backquote($sval); } else { $sql_query .= ', ' . PMA_backquote($sval); } } // what is this htmlspecialchars() for?? //$sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table)); $sql_query .= ' FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); require './sql.php'; exit; } else { // handle multiple field commands // handle confirmation of deleting multiple fields/columns $action = 'tbl_structure.php'; require './libraries/mult_submits.inc.php'; //require_once './libraries/header.inc.php'; //require_once './libraries/tbl_links.inc.php'; if (empty($message)) { $message = PMA_Message::success(); } }}/** * Gets the relation settings */$cfgRelation = PMA_getRelationsParam();/** * Runs common work */require_once './libraries/tbl_common.php';$url_query .= '&goto=tbl_structure.php&back=tbl_structure.php';$url_params['goto'] = 'tbl_structure.php';$url_params['back'] = 'tbl_structure.php';/** * Prepares the table structure display *//** * Gets tables informations */require_once './libraries/tbl_info.inc.php';/** * Displays top menu links */require_once './libraries/tbl_links.inc.php';require_once './libraries/Index.class.php';// 2. Gets table keys and retains them// @todo should be: $server->db($db)->table($table)->primary()$primary = PMA_Index::getPrimary($table, $db);// 3. Get fields$fields_rs = PMA_DBI_query('SHOW FULL FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);$fields_cnt = PMA_DBI_num_rows($fields_rs);// Get more complete field information// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options// but later, if the analyser returns more information, it// could be executed for any MySQL version and replace// the info given by SHOW FULL FIELDS FROM.//// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since// SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL// and SHOW CREATE TABLE says NOT NULL (tested// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).$show_create_table = PMA_DBI_fetch_value( 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1);$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));/** * prepare table infos */// action titles (image or string)$titles = array();$titles['Change'] = PMA_getIcon('b_edit.png', $strChange, true);$titles['Drop'] = PMA_getIcon('b_drop.png', $strDrop, true);$titles['NoDrop'] = PMA_getIcon('b_drop.png', $strDrop, true);$titles['Primary'] = PMA_getIcon('b_primary.png', $strPrimary, true);$titles['Index'] = PMA_getIcon('b_index.png', $strIndex, true);$titles['Unique'] = PMA_getIcon('b_unique.png', $strUnique, true);$titles['IdxFulltext'] = PMA_getIcon('b_ftext.png', $strIdxFulltext, true);$titles['NoPrimary'] = PMA_getIcon('bd_primary.png', $strPrimary, true);$titles['NoIndex'] = PMA_getIcon('bd_index.png', $strIndex, true);$titles['NoUnique'] = PMA_getIcon('bd_unique.png', $strUnique, true);$titles['NoIdxFulltext'] = PMA_getIcon('bd_ftext.png', $strIdxFulltext, true);$titles['BrowseDistinctValues'] = PMA_getIcon('b_browse.png', $strBrowseDistinctValues, true);/** * Displays the table structure ('show table' works correct since 3.23.03) *//* TABLE INFORMATION */// table header$i = 0;?><form method="post" action="tbl_structure.php" name="fieldsForm" id="fieldsForm"> <?php echo PMA_generate_common_hidden_inputs($db, $table); ?><table id="tablestructure" class="data"><thead><tr> <th id="th<?php echo ++$i; ?>"></th> <th id="th<?php echo ++$i; ?>"><?php echo $strField; ?></th> <th id="th<?php echo ++$i; ?>"><?php echo $strType; ?></th> <th id="th<?php echo ++$i; ?>"><?php echo $strCollation; ?></th> <th id="th<?php echo ++$i; ?>"><?php echo $strAttr; ?></th> <th id="th<?php echo ++$i; ?>"><?php echo $strNull; ?></th> <th id="th<?php echo ++$i; ?>"><?php echo $strDefault; ?></th> <th id="th<?php echo ++$i; ?>"><?php echo $strExtra; ?></th><?php if ($db_is_information_schema || $tbl_is_view) { ?> <th id="th<?php echo ++$i; ?>"><?php echo $strView; ?></th><?php } else { ?> <th colspan="7" id="th<?php echo ++$i; ?>"><?php echo $strAction; ?></th><?php } ?></tr></thead><tbody><?phpunset($i);// table body// prepare comments$comments_map = array();$mime_map = array();if ($GLOBALS['cfg']['ShowPropertyComments']) { require_once './libraries/relation.lib.php'; require_once './libraries/transformations.lib.php'; //$cfgRelation = PMA_getRelationsParam(); $comments_map = PMA_getComments($db, $table); if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) { $mime_map = PMA_getMIME($db, $table, true); }}$rownum = 0;$aryFields = array();$checked = (!empty($checkall) ? ' checked="checked"' : '');$save_row = array();$odd_row = true;while ($row = PMA_DBI_fetch_assoc($fields_rs)) { $save_row[] = $row; $rownum++; $aryFields[] = $row['Field']; $type = $row['Type']; $extracted_fieldspec = PMA_extractFieldSpec($row['Type']); if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) { $type = $extracted_fieldspec['type'] . '(' . $extracted_fieldspec['spec_in_brackets'] . ')'; // for the case ENUM('–','“') $type = htmlspecialchars($type); $type_nowrap = ''; $binary = 0; $unsigned = 0; $zerofill = 0; } else { $type_nowrap = ' nowrap="nowrap"'; // strip the "BINARY" attribute, except if we find "BINARY(" because // this would be a BINARY or VARBINARY field type if (!preg_match('@BINARY[\(]@i', $type)) { $type = preg_replace('@BINARY@i', '', $type); } $type = preg_replace('@ZEROFILL@i', '', $type); $type = preg_replace('@UNSIGNED@i', '', $type); if (empty($type)) { $type = ' '; } if (!preg_match('@BINARY[\(]@i', $row['Type'])) { $binary = stristr($row['Type'], 'blob') || stristr($row['Type'], 'binary'); } else { $binary = false; } $unsigned = stristr($row['Type'], 'unsigned'); $zerofill = stristr($row['Type'], 'zerofill'); } unset($field_charset); if ((substr($type, 0, 4) == 'char' || substr($type, 0, 7) == 'varchar' || substr($type, 0, 4) == 'text' || substr($type, 0, 8) == 'tinytext' || substr($type, 0, 10) == 'mediumtext' || substr($type, 0, 8) == 'longtext' || substr($type, 0, 3) == 'set' || substr($type, 0, 4) == 'enum' ) && !$binary) { if (strpos($type, ' character set ')) { $type = substr($type, 0, strpos($type, ' character set ')); } if (!empty($row['Collation'])) { $field_charset = $row['Collation']; } else { $field_charset = ''; } } else { $field_charset = ''; } // garvin: Display basic mimetype [MIME]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -