2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Renders data dictionary
8 declare(strict_types
=1);
10 use PhpMyAdmin\Relation
;
11 use PhpMyAdmin\Response
;
12 use PhpMyAdmin\Transformations
;
16 * Gets the variables sent or posted to this script, then displays headers
18 require_once 'libraries/common.inc.php';
20 if (! isset($selected_tbl)) {
21 include 'libraries/db_common.inc.php';
32 ) = PhpMyAdmin\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
35 $response = Response
::getInstance();
36 $header = $response->getHeader();
37 $header->enablePrintView();
39 $relation = new Relation($GLOBALS['dbi']);
40 $transformations = new Transformations();
43 * Gets the relations settings
45 $cfgRelation = $relation->getRelationsParam();
50 PhpMyAdmin\Util
::checkParameters(['db']);
53 * Defines the url to return to in case of error in a sql statement
55 $err_url = 'db_sql.php' . Url
::getCommon(['db' => $db]);
57 if ($cfgRelation['commwork']) {
58 $comment = $relation->getDbComment($db);
64 echo '<p>' , __('Database comment')
65 , '<br /><i>' , htmlspecialchars($comment) , '</i></p>';
70 * Selects the database and gets tables names
72 $GLOBALS['dbi']->selectDb($db);
73 $tables = $GLOBALS['dbi']->getTables($db);
76 foreach ($tables as $table) {
77 $comments = $relation->getComments($db, $table);
81 echo '<h2>' , htmlspecialchars($table) , '</h2>' , "\n";
84 * Gets table information
86 $show_comment = $GLOBALS['dbi']->getTable($db, $table)
87 ->getStatusInfo('TABLE_COMMENT');
90 * Gets table keys and retains them
92 $GLOBALS['dbi']->selectDb($db);
93 $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
94 list($primary, $pk_array, $indexes_info, $indexes_data)
95 = PhpMyAdmin\Util
::processIndexData($indexes);
98 * Gets columns properties
100 $columns = $GLOBALS['dbi']->getColumns($db, $table);
102 // Check if we can use Relations
103 list($res_rel, $have_rel) = $relation->getRelationsAndStatus(
104 ! empty($cfgRelation['relation']),
110 * Displays the comments of the table if MySQL >= 3.23
112 if (!empty($show_comment)) {
113 echo __('Table comments:') , ' ';
114 echo htmlspecialchars($show_comment) , '<br /><br />';
118 * Displays the table structure
121 echo '<table width="100%" class="print">';
122 echo '<tr><th width="50">' , __('Column') , '</th>';
123 echo '<th width="80">' , __('Type') , '</th>';
124 echo '<th width="40">' , __('Null') , '</th>';
125 echo '<th width="70">' , __('Default') , '</th>';
127 echo ' <th>' , __('Links to') , '</th>' , "\n";
129 echo ' <th>' , __('Comments') , '</th>' , "\n";
130 if ($cfgRelation['mimework']) {
131 echo ' <th>MIME</th>' , "\n";
134 foreach ($columns as $row) {
135 if ($row['Null'] == '') {
138 $extracted_columnspec
139 = PhpMyAdmin\Util
::extractColumnSpec($row['Type']);
141 // reformat mysql query output
142 // set or enum types: slashes single quotes inside options
144 $type = htmlspecialchars($extracted_columnspec['print_type']);
145 $attribute = $extracted_columnspec['attribute'];
146 if (! isset($row['Default'])) {
147 if ($row['Null'] != 'NO') {
148 $row['Default'] = '<i>NULL</i>';
151 $row['Default'] = htmlspecialchars($row['Default']);
153 $column_name = $row['Field'];
156 echo '<td class="nowrap">';
157 echo htmlspecialchars($column_name);
159 if (isset($pk_array[$row['Field']])) {
160 echo ' <em>(' , __('Primary') , ')</em>';
164 , PhpMyAdmin\Util
::getClassForType(
165 $extracted_columnspec['type']
167 , ' lang="en" dir="ltr">' , $type , '</td>';
170 echo (($row['Null'] == 'NO') ?
__('No') : __('Yes'));
172 echo '<td class="nowrap">';
173 if (isset($row['Default'])) {
174 echo $row['Default'];
180 if ($foreigner = $relation->searchColumnInForeigners($res_rel, $column_name)) {
181 echo htmlspecialchars(
182 $foreigner['foreign_table']
184 . $foreigner['foreign_field']
190 if (isset($comments[$column_name])) {
191 echo htmlspecialchars($comments[$column_name]);
194 if ($cfgRelation['mimework']) {
195 $mime_map = $transformations->getMime($db, $table, true);
198 if (isset($mime_map[$column_name])) {
199 echo htmlspecialchars(
200 str_replace('_', '/', $mime_map[$column_name]['mimetype'])
209 // display indexes information
210 if (count(PhpMyAdmin\Index
::getFromTable($table, $db)) > 0) {
211 echo PhpMyAdmin\Index
::getHtmlForIndexes($table, $db, true);
217 * Displays the footer
219 echo PhpMyAdmin\Util
::getButton();