Documentation TYPO3 par Ameos

db_datadict.php

00001 <?php
00002 /* $Id: db_datadict.php,v 2.5 2003/12/22 19:35:28 lem9 Exp $ */
00003 
00004 
00008 if (!isset($selected_tbl)) {
00009     require_once('./libraries/grab_globals.lib.php');
00010     require_once('./header.inc.php');
00011 }
00012 
00013 
00017 require_once('./libraries/relation.lib.php');
00018 require_once('./libraries/transformations.lib.php');
00019 
00020 $cfgRelation  = PMA_getRelationsParam();
00021 
00025 PMA_checkParameters(array('db'));
00026 
00030 if (isset($table)) {
00031     $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
00032 } else {
00033     $err_url = 'db_details.php?' . PMA_generate_common_url($db);
00034 }
00035 
00036 if ($cfgRelation['commwork']) {
00037     $comment = PMA_getComments($db);
00038 
00042     if (is_array($comment)) {
00043         ?>
00044     <!-- DB comment -->
00045     <p><?php echo $strDBComment; ?> <i>
00046         <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
00047     </i></p>
00048         <?php
00049     } // end if
00050 }
00051 
00055 PMA_mysql_select_db($db);
00056 $sql    = 'SHOW TABLES FROM ' . PMA_backquote($db);
00057 $rowset = @PMA_mysql_query($sql);
00058 
00059 if (!$rowset) {
00060     exit();
00061 }
00062 $count  = 0;
00063 while ($row = mysql_fetch_array($rowset)) {
00064     $myfieldname = 'Tables_in_' . htmlspecialchars($db);
00065     $table        = $row[$myfieldname];
00066     if ($cfgRelation['commwork']) {
00067         $comments = PMA_getComments($db, $table);
00068     }
00069 
00070     if ($count != 0) {
00071         echo '<div style="page-break-before: always">' . "\n";
00072     }
00073     echo '<h1>' . $table . '</h1>' . "\n";
00074 
00078     // The 'show table' statement works correct since 3.23.03
00079     $local_query  = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
00080     $result       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
00081     $showtable    = PMA_mysql_fetch_array($result);
00082     $num_rows     = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
00083     $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
00084     if ($result) {
00085          mysql_free_result($result);
00086     }
00087 
00088 
00092     $local_query  = 'SHOW KEYS FROM ' . PMA_backquote($table);
00093     $result       = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
00094     $primary      = '';
00095     $indexes      = array();
00096     $lastIndex    = '';
00097     $indexes_info = array();
00098     $indexes_data = array();
00099     $pk_array     = array(); // will be use to emphasis prim. keys in the table
00100                              // view
00101     while ($row = PMA_mysql_fetch_array($result)) {
00102         // Backups the list of primary keys
00103         if ($row['Key_name'] == 'PRIMARY') {
00104             $primary   .= $row['Column_name'] . ', ';
00105             $pk_array[$row['Column_name']] = 1;
00106         }
00107         // Retains keys informations
00108         if ($row['Key_name'] != $lastIndex ){
00109             $indexes[] = $row['Key_name'];
00110             $lastIndex = $row['Key_name'];
00111         }
00112         $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
00113         $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
00114         if (isset($row['Cardinality'])) {
00115             $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
00116         }
00117         // I don't know what does following column mean....
00118         // $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
00119 
00120         $indexes_info[$row['Key_name']]['Comment']     = $row['Comment'];
00121 
00122         $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
00123         if (isset($row['Sub_part'])) {
00124             $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
00125         }
00126 
00127     } // end while
00128     if ($result) {
00129         mysql_free_result($result);
00130     }
00131 
00132 
00136     $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
00137     $result      = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
00138     $fields_cnt  = mysql_num_rows($result);
00139 
00140     // Check if we can use Relations (Mike Beck)
00141     if (!empty($cfgRelation['relation'])) {
00142         // Find which tables are related with the current one and write it in
00143         // an array
00144         $res_rel = PMA_getForeigners($db, $table);
00145 
00146         if (count($res_rel) > 0) {
00147             $have_rel = TRUE;
00148         } else {
00149             $have_rel = FALSE;
00150         }
00151     }
00152     else {
00153         $have_rel = FALSE;
00154     } // end if
00155 
00156 
00160     if (!empty($show_comment)) {
00161         echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
00162     }
00163 
00167     ?>
00168 
00169 <!-- TABLE INFORMATIONS -->
00170 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse;background-color: white">
00171 <tr>
00172     <th width="50"><?php echo $strField; ?></th>
00173     <th width="80"><?php echo $strType; ?></th>
00174     <!--<th width="50"><?php echo $strAttr; ?></th>-->
00175     <th width="40"><?php echo $strNull; ?></th>
00176     <th width="70"><?php echo $strDefault; ?></th>
00177     <!--<th width="50"><?php echo $strExtra; ?></th>-->
00178     <?php
00179     echo "\n";
00180     if ($have_rel) {
00181         echo '    <th>' . $strLinksTo . '</th>' . "\n";
00182     }
00183     if ($cfgRelation['commwork']) {
00184         echo '    <th>' . $strComments . '</th>' . "\n";
00185     }
00186     if ($cfgRelation['mimework']) {
00187         echo '    <th>MIME</th>' . "\n";
00188     }
00189     ?>
00190 </tr>
00191 
00192     <?php
00193     $i = 0;
00194     while ($row = PMA_mysql_fetch_array($result)) {
00195         $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
00196         $i++;
00197 
00198         $type             = $row['Type'];
00199         // reformat mysql query output - staybyte - 9. June 2001
00200         // loic1: set or enum types: slashes single quotes inside options
00201         if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
00202             $tmp[2]       = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
00203             $type         = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
00204             $type_nowrap  = '';
00205 
00206             $binary       = 0;
00207             $unsigned     = 0;
00208             $zerofill     = 0;
00209         } else {
00210             $binary       = stristr($row['Type'], 'binary');
00211             $unsigned     = stristr($row['Type'], 'unsigned');
00212             $zerofill     = stristr($row['Type'], 'zerofill');
00213             $type_nowrap  = ' nowrap="nowrap"';
00214             $type         = preg_replace('@BINARY@i', '', $type);
00215             $type         = preg_replace('@ZEROFILL@i', '', $type);
00216             $type         = preg_replace('@UNSIGNED@i', '', $type);
00217             if (empty($type)) {
00218                 $type     = '&nbsp;';
00219             }
00220         }
00221         $strAttribute     = '&nbsp;';
00222         if ($binary) {
00223             $strAttribute = 'BINARY';
00224         }
00225         if ($unsigned) {
00226             $strAttribute = 'UNSIGNED';
00227         }
00228         if ($zerofill) {
00229             $strAttribute = 'UNSIGNED ZEROFILL';
00230         }
00231         if (!isset($row['Default'])) {
00232             if ($row['Null'] != '') {
00233                 $row['Default'] = '<i>NULL</i>';
00234             }
00235         } else {
00236             $row['Default'] = htmlspecialchars($row['Default']);
00237         }
00238         $field_name = htmlspecialchars($row['Field']);
00239         echo "\n";
00240         ?>
00241 <tr>
00242     <td width=50 class='print' nowrap="nowrap">
00243         <?php
00244         echo "\n";
00245         if (isset($pk_array[$row['Field']])) {
00246             echo '    <u>' . $field_name . '</u>&nbsp;' . "\n";
00247         } else {
00248             echo '    ' . $field_name . '&nbsp;' . "\n";
00249         }
00250         ?>
00251     </td>
00252     <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
00253     <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
00254     <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
00255     <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
00256     <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
00257         <?php
00258         echo "\n";
00259         if ($have_rel) {
00260             echo '    <td class="print">';
00261             if (isset($res_rel[$field_name])) {
00262                 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
00263             }
00264             echo '&nbsp;</td>' . "\n";
00265         }
00266         if ($cfgRelation['commwork']) {
00267             echo '    <td class="print">';
00268             if (isset($comments[$field_name])) {
00269                 echo htmlspecialchars($comments[$field_name]);
00270             }
00271             echo '&nbsp;</td>' . "\n";
00272         }
00273         if ($cfgRelation['mimework']) {
00274             $mime_map = PMA_getMIME($db, $table, true);
00275 
00276             echo '    <td class="print">';
00277             if (isset($mime_map[$field_name])) {
00278                 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
00279             }
00280             echo '&nbsp;</td>' . "\n";
00281         }
00282         ?>
00283 </tr>
00284         <?php
00285     } // end while
00286     mysql_free_result($result);
00287 
00288     echo "\n";
00289     ?>
00290 </table>
00291 
00292     <?php
00293     echo '</div>' . "\n";
00294 
00295     $count++;
00296 } //ends main while
00297 
00298 
00302 echo "\n";
00303 ?>
00304 <script type="text/javascript" language="javascript1.2">
00305 <!--
00306 function printPage()
00307 {
00308     document.getElementById('print').style.visibility = 'hidden';
00309     // Do print the page
00310     if (typeof(window.print) != 'undefined') {
00311         window.print();
00312     }
00313     document.getElementById('print').style.visibility = '';
00314 }
00315 //-->
00316 </script>
00317 <?php
00318 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
00319 
00320 require_once('./footer.inc.php');
00321 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6