2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/common.inc.php';
13 require './libraries/tbl_common.php';
16 * Gets the variables sent or posted to this script, then displays headers
19 if (! isset($selected_tbl)) {
20 require_once './libraries/header.inc.php';
25 if (! isset($the_tables) ||
! is_array($the_tables)) {
26 $the_tables = array();
30 * Gets the relations settings
32 require_once './libraries/transformations.lib.php';
33 require_once './libraries/Index.class.php';
35 $cfgRelation = PMA_getRelationsParam();
38 * Defines the url to return to in case of error in a sql statement
41 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
43 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
48 * Selects the database
50 PMA_DBI_select_db($db);
54 * Multi-tables printview
56 if (isset($selected_tbl) && is_array($selected_tbl)) {
57 $the_tables = $selected_tbl;
58 } elseif (strlen($table)) {
59 $the_tables[] = $table;
61 $multi_tables = (count($the_tables) > 1);
64 if (empty($GLOBALS['is_header_sent'])) {
65 require_once './libraries/header.inc.php';
68 foreach ($the_tables as $key => $table) {
69 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
70 . PMA_backquote($table);
72 echo '<strong>'. __('Show tables') . ': ' . htmlspecialchars($tbl_list) . '</strong>' . "\n";
76 $tables_cnt = count($the_tables);
79 foreach ($the_tables as $key => $table) {
80 if ($counter +
1 >= $tables_cnt) {
83 $breakstyle = ' style="page-break-after: always;"';
86 echo '<div' . $breakstyle . '>' . "\n";
87 echo '<h1>' . htmlspecialchars($table) . '</h1>' . "\n";
90 * Gets table informations
92 $showtable = PMA_Table
::sGetStatusInfo($db, $table);
93 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
94 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
96 $tbl_is_view = PMA_Table
::isView($db, $table);
99 * Gets fields properties
101 $result = PMA_DBI_query(
102 'SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null,
103 PMA_DBI_QUERY_STORE
);
104 $fields_cnt = PMA_DBI_num_rows($result);
107 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
108 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
109 // and SHOW CREATE TABLE says NOT NULL (tested
110 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
112 $show_create_table = PMA_DBI_fetch_value(
113 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
115 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
117 // Check if we can use Relations (Mike Beck)
118 // Find which tables are related with the current one and write it in
120 $res_rel = PMA_getForeigners($db, $table);
121 $have_rel = (bool) count($res_rel);
124 * Displays the comments of the table if MySQL >= 3.23
126 if (!empty($show_comment)) {
127 echo __('Table comments') . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
131 * Displays the table structure
135 <!-- TABLE INFORMATIONS
-->
136 <table style
="width: 100%;">
139 <th
><?php
echo __('Column'); ?
></th
>
140 <th
><?php
echo __('Type'); ?
></th
>
141 <!--<th
><?php
echo __('Attributes'); ?
></th
>-->
142 <th
><?php
echo __('Null'); ?
></th
>
143 <th
><?php
echo __('Default'); ?
></th
>
144 <!--<th
><?php
echo __('Extra'); ?
></th
>-->
147 echo '<th>' . __('Links to') . '</th>' . "\n";
149 echo ' <th>' . __('Comments') . '</th>' . "\n";
150 if ($cfgRelation['mimework']) {
151 echo ' <th>MIME</th>' . "\n";
158 while ($row = PMA_DBI_fetch_assoc($result)) {
159 $type = $row['Type'];
160 // reformat mysql query output
161 // set or enum types: slashes single quotes inside options
162 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
163 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'',
165 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
171 $type = preg_replace('@BINARY@i', '', $type);
172 $type = preg_replace('@ZEROFILL@i', '', $type);
173 $type = preg_replace('@UNSIGNED@i', '', $type);
178 $binary = stristr($row['Type'], 'binary');
179 $unsigned = stristr($row['Type'], 'unsigned');
180 $zerofill = stristr($row['Type'], 'zerofill');
182 $attribute = ' ';
184 $attribute = 'BINARY';
187 $attribute = 'UNSIGNED';
190 $attribute = 'UNSIGNED ZEROFILL';
192 if (!isset($row['Default'])) {
193 if ($row['Null'] != '' && $row['Null'] != 'NO') {
194 $row['Default'] = '<i>NULL</i>';
197 $row['Default'] = htmlspecialchars($row['Default']);
199 $field_name = htmlspecialchars($row['Field']);
201 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
202 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
205 * @todo merge this logic with the one in tbl_structure.php
206 * or move it in a function similar to PMA_DBI_get_columns_full()
207 * but based on SHOW CREATE TABLE because information_schema
208 * cannot be trusted in this case (MySQL bug)
210 if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
217 if (isset($pk_array[$row['Field']])) {
218 echo ' <u>' . $field_name . '</u>' . "\n";
220 echo ' ' . $field_name . "\n";
224 <td
><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
225 <!--<td
><?php
echo $attribute; ?
></td
>-->
226 <td
><?php
echo (($row['Null'] == '' ||
$row['Null'] == 'NO') ?
__('No') : __('Yes')); ?
> 
;</td
>
227 <td
><?php
if (isset($row['Default'])) { echo $row['Default']; } ?
> 
;</td
>
228 <!--<td
><?php
echo $row['Extra']; ?
> 
;</td
>-->
232 if (isset($res_rel[$field_name])) {
233 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
235 echo ' </td>' . "\n";
238 $comments = PMA_getComments($db, $table);
239 if (isset($comments[$field_name])) {
240 echo htmlspecialchars($comments[$field_name]);
242 echo ' </td>' . "\n";
243 if ($cfgRelation['mimework']) {
244 $mime_map = PMA_getMIME($db, $table, true);
247 if (isset($mime_map[$field_name])) {
248 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
250 echo ' </td>' . "\n";
256 PMA_DBI_free_result($result);
261 if (! $tbl_is_view && $db != 'information_schema') {
265 echo PMA_Index
::getView($table, $db, true);
268 * Displays Space usage and row statistics
271 if ($cfg['ShowStats']) {
273 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
276 if ($nonisam == false) {
279 $mergetable = PMA_Table
::isMerge($db, $table);
281 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
282 if ($mergetable == false) {
283 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
285 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
286 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
287 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
291 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
293 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
295 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
302 <table border
="0" cellspacing
="0" cellpadding
="0" class="noborder">
307 <big
><?php
echo __('Space usage') . ':'; ?
></big
>
310 <th
><?php
echo __('Type'); ?
></th
>
311 <th colspan
="2" align
="center"><?php
echo __('Usage'); ?
></th
>
314 <td style
="padding-right: 10px"><?php
echo __('Data'); ?
></td
>
315 <td align
="right"><?php
echo $data_size; ?
></td
>
316 <td
><?php
echo $data_unit; ?
></td
>
319 if (isset($index_size)) {
323 <td style
="padding-right: 10px"><?php
echo __('Index'); ?
></td
>
324 <td align
="right"><?php
echo $index_size; ?
></td
>
325 <td
><?php
echo $index_unit; ?
></td
>
329 if (isset($free_size)) {
332 <tr style
="color: #bb0000">
333 <td style
="padding-right: 10px"><?php
echo __('Overhead'); ?
></td
>
334 <td align
="right"><?php
echo $free_size; ?
></td
>
335 <td
><?php
echo $free_unit; ?
></td
>
338 <td style
="padding-right: 10px"><?php
echo __('Effective'); ?
></td
>
339 <td align
="right"><?php
echo $effect_size; ?
></td
>
340 <td
><?php
echo $effect_unit; ?
></td
>
344 if (isset($tot_size) && $mergetable == false) {
348 <td style
="padding-right: 10px"><?php
echo __('Total'); ?
></td
>
349 <td align
="right"><?php
echo $tot_size; ?
></td
>
350 <td
><?php
echo $tot_unit; ?
></td
>
359 <td width
="20"> 
;</td
>
361 <!-- Rows Statistic
-->
363 <big
><?php
echo __('Row Statistics') . ':'; ?
></big
>
366 <th
><?php
echo __('Statements'); ?
></th
>
367 <th align
="center"><?php
echo __('Value'); ?
></th
>
370 if (isset($showtable['Row_format'])) {
373 <td
><?php
echo ucfirst(__('Format')); ?
></td
>
374 <td align
="<?php echo $cell_align_left; ?>">
376 if ($showtable['Row_format'] == 'Fixed') {
378 } elseif ($showtable['Row_format'] == 'Dynamic') {
381 echo $showtable['Row_format'];
388 if (isset($showtable['Rows'])) {
391 <td
><?php
echo ucfirst(__('Rows')); ?
></td
>
393 <?php
echo PMA_formatNumber($showtable['Rows'], 0) . "\n"; ?
>
398 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
401 <td
><?php
echo ucfirst(__('Row length')); ?
> 
;ø
;</td
>
403 <?php
echo PMA_formatNumber($showtable['Avg_row_length'], 0) . "\n"; ?
>
408 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == false) {
411 <td
><?php
echo ucfirst(__(' Row size ')); ?
> 
;ø
;</td
>
413 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
418 if (isset($showtable['Auto_increment'])) {
421 <td
><?php
echo ucfirst(__('Next')); ?
> 
;Autoindex
</td
>
423 <?php
echo PMA_formatNumber($showtable['Auto_increment'], 0) . "\n"; ?
>
428 if (isset($showtable['Create_time'])) {
431 <td
><?php
echo __('Creation'); ?
></td
>
433 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
438 if (isset($showtable['Update_time'])) {
441 <td
><?php
echo __('Last update'); ?
></td
>
443 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
448 if (isset($showtable['Check_time'])) {
451 <td
><?php
echo __('Last check'); ?
></td
>
453 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
466 } // end if ($nonisam == false)
467 } // end if ($cfg['ShowStats'])
470 unset($num_rows, $show_comment);
471 echo '<hr />' . "\n";
473 echo '</div>' . "\n";
478 * Displays the footer
482 <script type
="text/javascript">
487 if (typeof(window
.print) != 'undefined') {
494 <p
class="print_ignore">
495 <input type
="button" id
="print" value
="<?php echo __('Print'); ?>"
496 onclick
="printPage()" /></p
>
499 require './libraries/footer.inc.php';