PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/pma/db_datadict.php

https://bitbucket.org/StasPiv/playzone
PHP | 325 lines | 221 code | 35 blank | 69 comment | 54 complexity | 22b0b4bd7ed0743d8cae30aebf888eeb MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @version $Id: db_datadict.php 12120 2008-12-10 09:22:29Z cybot_tm $
  6. * @package phpMyAdmin
  7. */
  8. /**
  9. * Gets the variables sent or posted to this script, then displays headers
  10. */
  11. require_once './libraries/common.inc.php';
  12. if (!isset($selected_tbl)) {
  13. require_once './libraries/header.inc.php';
  14. }
  15. /**
  16. * Gets the relations settings
  17. */
  18. require_once './libraries/relation.lib.php';
  19. require_once './libraries/transformations.lib.php';
  20. $cfgRelation = PMA_getRelationsParam();
  21. /**
  22. * Check parameters
  23. */
  24. PMA_checkParameters(array('db'));
  25. /**
  26. * Defines the url to return to in case of error in a sql statement
  27. */
  28. if (strlen($table)) {
  29. $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
  30. } else {
  31. $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
  32. }
  33. if ($cfgRelation['commwork']) {
  34. $comment = PMA_getDbComment($db);
  35. /**
  36. * Displays DB comment
  37. */
  38. if ($comment) {
  39. ?>
  40. <p> <?php echo $strDBComment; ?>
  41. <i><?php echo htmlspecialchars($comment); ?></i></p>
  42. <?php
  43. } // end if
  44. }
  45. /**
  46. * Selects the database and gets tables names
  47. */
  48. PMA_DBI_select_db($db);
  49. $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
  50. $count = 0;
  51. while ($row = PMA_DBI_fetch_assoc($rowset)) {
  52. $myfieldname = 'Tables_in_' . htmlspecialchars($db);
  53. $table = $row[$myfieldname];
  54. $comments = PMA_getComments($db, $table);
  55. if ($count != 0) {
  56. echo '<div style="page-break-before: always;">' . "\n";
  57. } else {
  58. echo '<div>' . "\n";
  59. }
  60. echo '<h2>' . $table . '</h2>' . "\n";
  61. /**
  62. * Gets table informations
  63. */
  64. // The 'show table' statement works correct since 3.23.03
  65. $num_rows = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_ROWS');
  66. $show_comment = PMA_Table::sGetStatusInfo($db, $table, 'TABLE_COMMENT');
  67. /**
  68. * Gets table keys and retains them
  69. */
  70. PMA_DBI_select_db($db);
  71. $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
  72. $primary = '';
  73. $indexes = array();
  74. $lastIndex = '';
  75. $indexes_info = array();
  76. $indexes_data = array();
  77. $pk_array = array(); // will be use to emphasis prim. keys in the table
  78. // view
  79. while ($row = PMA_DBI_fetch_assoc($result)) {
  80. // Backups the list of primary keys
  81. if ($row['Key_name'] == 'PRIMARY') {
  82. $primary .= $row['Column_name'] . ', ';
  83. $pk_array[$row['Column_name']] = 1;
  84. }
  85. // Retains keys informations
  86. if ($row['Key_name'] != $lastIndex){
  87. $indexes[] = $row['Key_name'];
  88. $lastIndex = $row['Key_name'];
  89. }
  90. $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
  91. $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
  92. if (isset($row['Cardinality'])) {
  93. $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
  94. }
  95. // I don't know what does following column mean....
  96. // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
  97. $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
  98. $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
  99. if (isset($row['Sub_part'])) {
  100. $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
  101. }
  102. } // end while
  103. if ($result) {
  104. PMA_DBI_free_result($result);
  105. }
  106. /**
  107. * Gets fields properties
  108. */
  109. $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
  110. $fields_cnt = PMA_DBI_num_rows($result);
  111. if (PMA_MYSQL_INT_VERSION < 50025) {
  112. // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
  113. // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
  114. // and SHOW CREATE TABLE says NOT NULL
  115. // http://bugs.mysql.com/20910.
  116. $show_create_table = PMA_DBI_fetch_value(
  117. 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
  118. 0, 1);
  119. $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  120. }
  121. // Check if we can use Relations (Mike Beck)
  122. if (!empty($cfgRelation['relation'])) {
  123. // Find which tables are related with the current one and write it in
  124. // an array
  125. $res_rel = PMA_getForeigners($db, $table);
  126. if (count($res_rel) > 0) {
  127. $have_rel = TRUE;
  128. } else {
  129. $have_rel = FALSE;
  130. }
  131. } else {
  132. $have_rel = FALSE;
  133. } // end if
  134. /**
  135. * Displays the comments of the table if MySQL >= 3.23
  136. */
  137. if (!empty($show_comment)) {
  138. echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
  139. }
  140. /**
  141. * Displays the table structure
  142. */
  143. ?>
  144. <table width="100%" class="print">
  145. <tr><th width="50"><?php echo $strField; ?></th>
  146. <th width="80"><?php echo $strType; ?></th>
  147. <?php /* <th width="50"><?php echo $strAttr; ?></th>*/ ?>
  148. <th width="40"><?php echo $strNull; ?></th>
  149. <th width="70"><?php echo $strDefault; ?></th>
  150. <?php /* <th width="50"><?php echo $strExtra; ?></th>*/ ?>
  151. <?php
  152. if ($have_rel) {
  153. echo ' <th>' . $strLinksTo . '</th>' . "\n";
  154. }
  155. echo ' <th>' . $strComments . '</th>' . "\n";
  156. if ($cfgRelation['mimework']) {
  157. echo ' <th>MIME</th>' . "\n";
  158. }
  159. ?>
  160. </tr>
  161. <?php
  162. $odd_row = true;
  163. while ($row = PMA_DBI_fetch_assoc($result)) {
  164. if ($row['Null'] == '') {
  165. $row['Null'] = 'NO';
  166. }
  167. $type = $row['Type'];
  168. // reformat mysql query output - staybyte - 9. June 2001
  169. // loic1: set or enum types: slashes single quotes inside options
  170. if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
  171. $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
  172. $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
  173. $type_nowrap = '';
  174. $binary = 0;
  175. $unsigned = 0;
  176. $zerofill = 0;
  177. } else {
  178. $binary = stristr($row['Type'], 'binary');
  179. $unsigned = stristr($row['Type'], 'unsigned');
  180. $zerofill = stristr($row['Type'], 'zerofill');
  181. $type_nowrap = ' nowrap="nowrap"';
  182. $type = preg_replace('@BINARY@i', '', $type);
  183. $type = preg_replace('@ZEROFILL@i', '', $type);
  184. $type = preg_replace('@UNSIGNED@i', '', $type);
  185. if (empty($type)) {
  186. $type = ' ';
  187. }
  188. }
  189. $strAttribute = ' ';
  190. if ($binary) {
  191. $strAttribute = 'BINARY';
  192. }
  193. if ($unsigned) {
  194. $strAttribute = 'UNSIGNED';
  195. }
  196. if ($zerofill) {
  197. $strAttribute = 'UNSIGNED ZEROFILL';
  198. }
  199. if (!isset($row['Default'])) {
  200. if ($row['Null'] != 'NO') {
  201. $row['Default'] = '<i>NULL</i>';
  202. }
  203. } else {
  204. $row['Default'] = htmlspecialchars($row['Default']);
  205. }
  206. $field_name = htmlspecialchars($row['Field']);
  207. if (PMA_MYSQL_INT_VERSION < 50025
  208. && ! empty($analyzed_sql[0]['create_table_fields'][$field_name]['type'])
  209. && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP'
  210. && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
  211. // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
  212. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  213. // the latter.
  214. /**
  215. * @todo merge this logic with the one in tbl_structure.php
  216. * or move it in a function similar to PMA_DBI_get_columns_full()
  217. * but based on SHOW CREATE TABLE because information_schema
  218. * cannot be trusted in this case (MySQL bug)
  219. */
  220. $row['Null'] = 'NO';
  221. }
  222. ?>
  223. <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
  224. <td nowrap="nowrap">
  225. <?php
  226. if (isset($pk_array[$row['Field']])) {
  227. echo '<u>' . $field_name . '</u>';
  228. } else {
  229. echo $field_name;
  230. }
  231. ?>
  232. </td>
  233. <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
  234. <?php /* <td<?php echo $type_nowrap; ?>><?php echo $strAttribute; ?></td>*/ ?>
  235. <td><?php echo (($row['Null'] == 'NO') ? $strNo : $strYes); ?></td>
  236. <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
  237. <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
  238. <?php
  239. if ($have_rel) {
  240. echo ' <td>';
  241. if (isset($res_rel[$field_name])) {
  242. echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
  243. }
  244. echo '</td>' . "\n";
  245. }
  246. echo ' <td>';
  247. if (isset($comments[$field_name])) {
  248. echo htmlspecialchars($comments[$field_name]);
  249. }
  250. echo '</td>' . "\n";
  251. if ($cfgRelation['mimework']) {
  252. $mime_map = PMA_getMIME($db, $table, true);
  253. echo ' <td>';
  254. if (isset($mime_map[$field_name])) {
  255. echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
  256. }
  257. echo '</td>' . "\n";
  258. }
  259. ?>
  260. </tr>
  261. <?php
  262. } // end while
  263. PMA_DBI_free_result($result);
  264. $count++;
  265. ?>
  266. </table>
  267. </div>
  268. <?php
  269. } //ends main while
  270. /**
  271. * Displays the footer
  272. */
  273. ?>
  274. <script type="text/javascript">
  275. //<![CDATA[
  276. function printPage()
  277. {
  278. document.getElementById('print').style.visibility = 'hidden';
  279. // Do print the page
  280. if (typeof(window.print) != 'undefined') {
  281. window.print();
  282. }
  283. document.getElementById('print').style.visibility = '';
  284. }
  285. //]]>
  286. </script>
  287. <?php
  288. echo '<br /><br /><input type="button" id="print" value="' . $strPrint . '" onclick="printPage()" />';
  289. require_once './libraries/footer.inc.php';
  290. ?>