Added faq 1.27 about GZIP output buffering problem.
[phpmyadmin/crack.git] / db_datadict.php3
blob41a56b8d7cc3d9c9afeba136bc4f8013cd05754b
1 <?php
2 /* $Id$ */
5 /**
6 * Gets the variables sent or posted to this script, then displays headers
7 */
8 if (!isset($selected_tbl)) {
9 include('./libraries/grab_globals.lib.php3');
10 include('./header.inc.php3');
14 /**
15 * Gets the relations settings
17 require('./libraries/relation.lib.php3');
20 /**
21 * Defines the url to return to in case of error in a sql statement
23 if (isset($table)) {
24 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
25 } else {
26 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
30 /**
31 * Selects the database and gets tables names
33 PMA_mysql_select_db($db);
34 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
35 $rowset = mysql_query($sql);
36 $count = 0;
37 while ($row = mysql_fetch_array($rowset)) {
38 if (PMA_MYSQL_INT_VERSION >= 32303) {
39 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
41 else {
42 $myfieldname = 'Tables in ' . htmlspecialchars($db);
44 $table = $row[$myfieldname];
45 $cfgRelation = PMA_getRelationsParam();
46 if ($cfgRelation['commwork']) {
47 $comments = PMA_getComments($db, $table);
50 if ($count != 0) {
51 echo '<div style="page-break-before: always">' . "\n";
53 echo '<h1>' . $table . '</h1>' . "\n";
55 /**
56 * Gets table informations
58 // The 'show table' statement works correct since 3.23.03
59 if (PMA_MYSQL_INT_VERSION >= 32303) {
60 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
61 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
62 $showtable = PMA_mysql_fetch_array($result);
63 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
64 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
65 } else {
66 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
67 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
68 $showtable = array();
69 $num_rows = PMA_mysql_result($result, 0, 'count');
70 $show_comment = '';
71 } // end display comments
72 if ($result) {
73 mysql_free_result($result);
77 /**
78 * Gets table keys and retains them
80 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
81 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
82 $primary = '';
83 $indexes = array();
84 $lastIndex = '';
85 $indexes_info = array();
86 $indexes_data = array();
87 $pk_array = array(); // will be use to emphasis prim. keys in the table
88 // view
89 while ($row = PMA_mysql_fetch_array($result)) {
90 // Backups the list of primary keys
91 if ($row['Key_name'] == 'PRIMARY') {
92 $primary .= $row['Column_name'] . ', ';
93 $pk_array[$row['Column_name']] = 1;
95 // Retains keys informations
96 if ($row['Key_name'] != $lastIndex ){
97 $indexes[] = $row['Key_name'];
98 $lastIndex = $row['Key_name'];
100 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
101 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
102 if (isset($row['Cardinality'])) {
103 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
105 // I don't know what does following column mean....
106 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
107 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
109 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
110 if (isset($row['Sub_part'])) {
111 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
114 } // end while
115 if ($result) {
116 mysql_free_result($result);
121 * Gets fields properties
123 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
124 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
125 $fields_cnt = mysql_num_rows($result);
127 // Check if we can use Relations (Mike Beck)
128 if (!empty($cfgRelation['relation'])) {
129 // Find which tables are related with the current one and write it in
130 // an array
131 $res_rel = PMA_getForeigners($db, $table);
133 if (count($res_rel) > 0) {
134 $have_rel = TRUE;
135 } else {
136 $have_rel = FALSE;
139 else {
140 $have_rel = FALSE;
141 } // end if
145 * Displays the comments of the table if MySQL >= 3.23
147 if (!empty($show_comment)) {
148 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
152 * Displays the table structure
156 <!-- TABLE INFORMATIONS -->
157 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse;background-color: white">
158 <tr>
159 <th width="50"><?php echo $strField; ?></th>
160 <th width="80"><?php echo $strType; ?></th>
161 <!--<th width="50"><?php echo $strAttr; ?></th>-->
162 <th width="40"><?php echo $strNull; ?></th>
163 <th width="70"><?php echo $strDefault; ?></th>
164 <!--<th width="50"><?php echo $strExtra; ?></th>-->
165 <?php
166 echo "\n";
167 if ($have_rel) {
168 echo ' <th>' . $strLinksTo . '</th>' . "\n";
170 if ($cfgRelation['commwork']) {
171 echo ' <th>' . $strComments . '</th>' . "\n";
174 </tr>
176 <?php
177 $i = 0;
178 while ($row = PMA_mysql_fetch_array($result)) {
179 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
180 $i++;
182 $type = $row['Type'];
183 // reformat mysql query output - staybyte - 9. June 2001
184 // loic1: set or enum types: slashes single quotes inside options
185 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
186 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
187 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
188 $type_nowrap = '';
190 $binary = 0;
191 $unsigned = 0;
192 $zerofill = 0;
193 } else {
194 $binary = eregi('BINARY', $row['Type'], $test);
195 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
196 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
197 $type_nowrap = ' nowrap="nowrap"';
198 $type = eregi_replace('BINARY', '', $type);
199 $type = eregi_replace('ZEROFILL', '', $type);
200 $type = eregi_replace('UNSIGNED', '', $type);
201 if (empty($type)) {
202 $type = '&nbsp;';
205 $strAttribute = '&nbsp;';
206 if ($binary) {
207 $strAttribute = 'BINARY';
209 if ($unsigned) {
210 $strAttribute = 'UNSIGNED';
212 if ($zerofill) {
213 $strAttribute = 'UNSIGNED ZEROFILL';
215 if (!isset($row['Default'])) {
216 if ($row['Null'] != '') {
217 $row['Default'] = '<i>NULL</i>';
219 } else {
220 $row['Default'] = htmlspecialchars($row['Default']);
222 $field_name = htmlspecialchars($row['Field']);
223 echo "\n";
225 <tr>
226 <td width=50 class='print' nowrap="nowrap">
227 <?php
228 echo "\n";
229 if (isset($pk_array[$row['Field']])) {
230 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
231 } else {
232 echo ' ' . $field_name . '&nbsp;' . "\n";
235 </td>
236 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
237 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
238 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
239 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
240 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
241 <?php
242 echo "\n";
243 if ($have_rel) {
244 echo ' <td class="print">';
245 if (isset($res_rel[$field_name])) {
246 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
248 echo '&nbsp;</td>' . "\n";
250 if ($cfgRelation['commwork']) {
251 echo ' <td class="print">';
252 if (isset($comments[$field_name])) {
253 echo htmlspecialchars($comments[$field_name]);
255 echo '&nbsp;</td>' . "\n";
258 </tr>
259 <?php
260 } // end while
261 mysql_free_result($result);
263 echo "\n";
265 </table>
267 <?php
268 echo '</div>' . "\n";
270 $count++;
271 } //ends main while
275 * Displays the footer
277 echo "\n";
279 <script type="text/javascript" language="javascript1.2">
280 <!--
281 function printPage()
283 document.all.print.style.visibility = 'hidden';
284 // Do print the page
285 if (typeof(window.print) != 'undefined') {
286 window.print();
288 document.all.print.style.visibility = '';
290 //-->
291 </script>
292 <?php
293 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
295 require('./footer.inc.php3');