6 * Gets the variables sent or posted to this script, then displays headers
8 if (!isset($selected_tbl)) {
9 include('./libraries/grab_globals.lib.php3');
10 include('./header.inc.php3');
15 * Gets the relations settings
17 require('./libraries/relation.lib.php3');
21 * Defines the url to return to in case of error in a sql statement
24 $err_url = 'tbl_properties.php3'
26 . '&convcharset=' . $convcharset
27 . '&server=' . $server
28 . '&db=' . urlencode($db)
29 . '&table=' . urlencode($table);
31 $err_url = 'db_details.php3'
33 . '&convcharset=' . $convcharset
34 . '&server=' . $server
35 . '&db=' . urlencode($db);
40 * Selects the database and gets tables names
42 PMA_mysql_select_db($db);
43 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
44 $rowset = mysql_query($sql);
46 while ($row = mysql_fetch_array($rowset)) {
47 if (PMA_MYSQL_INT_VERSION
>= 32303) {
48 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
51 $myfieldname = 'Tables in ' . htmlspecialchars($db);
53 $table = $row[$myfieldname];
54 $cfgRelation = PMA_getRelationsParam();
55 if ($cfgRelation['commwork']) {
56 $comments = PMA_getComments($db, $table);
60 echo '<div style="page-break-before: always">' . "\n";
62 echo '<h1>' . $table . '</h1>' . "\n";
65 * Gets table informations
67 // The 'show table' statement works correct since 3.23.03
68 if (PMA_MYSQL_INT_VERSION
>= 32303) {
69 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
70 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
71 $showtable = PMA_mysql_fetch_array($result);
72 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
73 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
75 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
76 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
78 $num_rows = PMA_mysql_result($result, 0, 'count');
80 } // end display comments
82 mysql_free_result($result);
87 * Gets table keys and retains them
89 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
90 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
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_mysql_fetch_array($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'];
116 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
118 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
119 if (isset($row['Sub_part'])) {
120 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
125 mysql_free_result($result);
130 * Gets fields properties
132 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
133 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
134 $fields_cnt = mysql_num_rows($result);
136 // Check if we can use Relations (Mike Beck)
137 if (!empty($cfgRelation['relation'])) {
138 // Find which tables are related with the current one and write it in
140 $res_rel = PMA_getForeigners($db, $table);
142 if (count($res_rel) > 0) {
154 * Displays the comments of the table if MySQL >= 3.23
156 if (!empty($show_comment)) {
157 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
161 * Displays the table structure
165 <!-- TABLE INFORMATIONS
-->
166 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse;background-color: white">
168 <th width
="50"><?php
echo ucfirst($strField); ?
></th
>
169 <th width
="50"><?php
echo ucfirst($strType); ?
></th
>
170 <!--<th width
="50"><?php
echo ucfirst($strAttr); ?
></th
>-->
171 <th width
="50"><?php
echo ucfirst($strNull); ?
></th
>
172 <th width
="50"><?php
echo ucfirst($strDefault); ?
></th
>
173 <!--<th width
="50"><?php
echo ucfirst($strExtra); ?
></th
>-->
177 echo ' <th width="50">' . ucfirst($strLinksTo) . '</th>' . "\n";
179 if ($cfgRelation['commwork']) {
180 echo ' <th width="400">' . ucfirst($strComments) . '</th>' . "\n";
187 while ($row = PMA_mysql_fetch_array($result)) {
188 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
191 $type = $row['Type'];
192 // reformat mysql query output - staybyte - 9. June 2001
193 // loic1: set or enum types: slashes single quotes inside options
194 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
195 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
196 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
199 $type_nowrap = ' nowrap="nowrap"';
201 $type = eregi_replace('BINARY', '', $type);
202 $type = eregi_replace('ZEROFILL', '', $type);
203 $type = eregi_replace('UNSIGNED', '', $type);
208 $binary = eregi('BINARY', $row['Type'], $test);
209 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
210 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
211 $strAttribute = ' ';
213 $strAttribute = 'BINARY';
216 $strAttribute = 'UNSIGNED';
219 $strAttribute = 'UNSIGNED ZEROFILL';
221 if (!isset($row['Default'])) {
222 if ($row['Null'] != '') {
223 $row['Default'] = '<i>NULL</i>';
226 $row['Default'] = htmlspecialchars($row['Default']);
228 $field_name = htmlspecialchars($row['Field']);
232 <td width
=50 class='print' nowrap
="nowrap">
235 if (isset($pk_array[$row['Field']])) {
236 echo ' <u>' . $field_name . '</u> ' . "\n";
238 echo ' ' . $field_name . ' ' . "\n";
242 <td width
="50" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
243 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
244 <td width
="50" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
245 <td width
="50" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
246 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
250 echo ' <td width="50" class="print">';
251 if (isset($res_rel[$field_name])) {
252 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
254 echo ' </td>' . "\n";
256 if ($cfgRelation['commwork']) {
257 echo ' <td width="400" class="print">';
258 if (isset($comments[$field_name])) {
259 echo htmlspecialchars($comments[$field_name]);
261 echo ' </td>' . "\n";
267 mysql_free_result($result);
274 echo '</div>' . "\n";
281 * Displays the footer
285 <script type
="text/javascript" language
="javascript1.2">
289 document
.all
.print.style
.visibility
= 'hidden';
291 if (typeof(window
.print) != 'undefined') {
294 document
.all
.print.style
.visibility
= '';
299 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
301 require('./footer.inc.php3');