2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 * Gets the variables sent or posted to this script, then displays headers
12 require_once './libraries/common.inc.php';
14 if (!isset($selected_tbl)) {
15 require_once './libraries/header.inc.php';
20 * Gets the relations settings
22 require_once './libraries/relation.lib.php';
23 require_once './libraries/transformations.lib.php';
25 $cfgRelation = PMA_getRelationsParam();
30 PMA_checkParameters(array('db'));
33 * Defines the url to return to in case of error in a sql statement
36 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
38 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
41 if ($cfgRelation['commwork']) {
42 $comment = PMA_getDbComment($db);
49 <p
> <?php
echo $strDBComment; ?
>
50 <i
><?php
echo htmlspecialchars($comment); ?
></i
></p
>
56 * Selects the database and gets tables names
58 PMA_DBI_select_db($db);
59 $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE
);
62 while ($row = PMA_DBI_fetch_assoc($rowset)) {
63 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
64 $table = $row[$myfieldname];
65 $comments = PMA_getComments($db, $table);
68 echo '<div style="page-break-before: always;">' . "\n";
73 echo '<h2>' . $table . '</h2>' . "\n";
76 * Gets table informations
78 // The 'show table' statement works correct since 3.23.03
79 $showtable = PMA_DBI_get_tables_full($db, $table);
80 $num_rows = (isset($showtable[$table]['TABLE_ROWS']) ?
$showtable[$table]['TABLE_ROWS'] : 0);
81 $show_comment = (isset($showtable[$table]['TABLE_COMMENT']) ?
$showtable[$table]['TABLE_COMMENT'] : '');
86 * Gets table keys and retains them
89 PMA_DBI_select_db($db);
90 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
94 $indexes_info = array();
95 $indexes_data = array();
96 $pk_array = array(); // will be use to emphasis prim. keys in the table
98 while ($row = PMA_DBI_fetch_assoc($result)) {
99 // Backups the list of primary keys
100 if ($row['Key_name'] == 'PRIMARY') {
101 $primary .= $row['Column_name'] . ', ';
102 $pk_array[$row['Column_name']] = 1;
104 // Retains keys informations
105 if ($row['Key_name'] != $lastIndex){
106 $indexes[] = $row['Key_name'];
107 $lastIndex = $row['Key_name'];
109 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
110 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
111 if (isset($row['Cardinality'])) {
112 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
114 // I don't know what does following column mean....
115 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
117 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
119 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
120 if (isset($row['Sub_part'])) {
121 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
126 PMA_DBI_free_result($result);
131 * Gets fields properties
133 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE
);
134 $fields_cnt = PMA_DBI_num_rows($result);
136 if (PMA_MYSQL_INT_VERSION
< 50025) {
137 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
138 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
139 // and SHOW CREATE TABLE says NOT NULL
140 // http://bugs.mysql.com/20910.
142 $show_create_table = PMA_DBI_fetch_value(
143 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
145 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
148 // Check if we can use Relations (Mike Beck)
149 if (!empty($cfgRelation['relation'])) {
150 // Find which tables are related with the current one and write it in
152 $res_rel = PMA_getForeigners($db, $table);
154 if (count($res_rel) > 0) {
165 * Displays the comments of the table if MySQL >= 3.23
167 if (!empty($show_comment)) {
168 echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
172 * Displays the table structure
176 <table width
="100%" class="print">
177 <tr
><th width
="50"><?php
echo $strField; ?
></th
>
178 <th width
="80"><?php
echo $strType; ?
></th
>
179 <?php
/* <th width="50"><?php echo $strAttr; ?></th>*/ ?
>
180 <th width
="40"><?php
echo $strNull; ?
></th
>
181 <th width
="70"><?php
echo $strDefault; ?
></th
>
182 <?php
/* <th width="50"><?php echo $strExtra; ?></th>*/ ?
>
185 echo ' <th>' . $strLinksTo . '</th>' . "\n";
187 echo ' <th>' . $strComments . '</th>' . "\n";
188 if ($cfgRelation['mimework']) {
189 echo ' <th>MIME</th>' . "\n";
195 while ($row = PMA_DBI_fetch_assoc($result)) {
197 if ($row['Null'] == '') {
200 $type = $row['Type'];
201 // reformat mysql query output - staybyte - 9. June 2001
202 // loic1: set or enum types: slashes single quotes inside options
203 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
204 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
205 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
212 $binary = stristr($row['Type'], 'binary');
213 $unsigned = stristr($row['Type'], 'unsigned');
214 $zerofill = stristr($row['Type'], 'zerofill');
215 $type_nowrap = ' nowrap="nowrap"';
216 $type = preg_replace('@BINARY@i', '', $type);
217 $type = preg_replace('@ZEROFILL@i', '', $type);
218 $type = preg_replace('@UNSIGNED@i', '', $type);
225 $strAttribute = 'BINARY';
228 $strAttribute = 'UNSIGNED';
231 $strAttribute = 'UNSIGNED ZEROFILL';
233 if (!isset($row['Default'])) {
234 if ($row['Null'] != 'NO') {
235 $row['Default'] = '<i>NULL</i>';
238 $row['Default'] = htmlspecialchars($row['Default']);
240 $field_name = htmlspecialchars($row['Field']);
242 if (PMA_MYSQL_INT_VERSION
< 50025
243 && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
244 && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
245 && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
246 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
247 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
250 * @todo merge this logic with the one in tbl_structure.php
251 * or move it in a function similar to PMA_DBI_get_columns_full()
252 * but based on SHOW CREATE TABLE because information_schema
253 * cannot be trusted in this case (MySQL bug)
258 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
261 if (isset($pk_array[$row['Field']])) {
262 echo '<u>' . $field_name . '</u>';
268 <td
<?php
echo $type_nowrap; ?
> xml
:lang
="en" dir
="ltr"><?php
echo $type; ?
></td
>
269 <?php
/* <td<?php echo $type_nowrap; ?>><?php echo $strAttribute; ?></td>*/ ?
>
270 <td
><?php
echo (($row['Null'] == 'NO') ?
$strNo : $strYes); ?
></td
>
271 <td nowrap
="nowrap"><?php
if (isset($row['Default'])) { echo $row['Default']; } ?
></td
>
272 <?php
/* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?
>
276 if (isset($res_rel[$field_name])) {
277 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
282 if (isset($comments[$field_name])) {
283 echo htmlspecialchars($comments[$field_name]);
286 if ($cfgRelation['mimework']) {
287 $mime_map = PMA_getMIME($db, $table, true);
290 if (isset($mime_map[$field_name])) {
291 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
299 PMA_DBI_free_result($result);
308 * Displays the footer
311 <script type
="text/javascript">
315 document
.getElementById('print').style
.visibility
= 'hidden';
317 if (typeof(window
.print) != 'undefined') {
320 document
.getElementById('print').style
.visibility
= '';
325 echo '<br /><br /><input type="button" id="print" value="' . $strPrint . '" onclick="printPage()" />';
327 require_once './libraries/footer.inc.php';