db_printview.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. /**
  8. *
  9. */
  10. require_once 'libraries/common.inc.php';
  11. $response = PMA_Response::getInstance();
  12. $header = $response->getHeader();
  13. $header->enablePrintView();
  14. PMA_Util::checkParameters(array('db'));
  15. /**
  16. * Defines the url to return to in case of error in a sql statement
  17. */
  18. $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
  19. /**
  20. * Settings for relations stuff
  21. */
  22. $cfgRelation = PMA_getRelationsParam();
  23. /**
  24. * Gets the list of the table in the current db and informations about these
  25. * tables if possible
  26. *
  27. * @todo merge this speedup _optionaly_ into PMA_DBI_get_tables_full()
  28. *
  29. // speedup view on locked tables
  30. // Special speedup for newer MySQL Versions (in 4.0 format changed)
  31. if ($cfg['SkipLockedTables'] == true) {
  32. $result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_Util::backquote($db) . ';');
  33. // Blending out tables in use
  34. if ($result != false && PMA_DBI_num_rows($result) > 0) {
  35. while ($tmp = PMA_DBI_fetch_row($result)) {
  36. // if in use memorize tablename
  37. if (preg_match('@in_use=[1-9]+@i', $tmp[0])) {
  38. $sot_cache[$tmp[0]] = true;
  39. }
  40. }
  41. PMA_DBI_free_result($result);
  42. if (isset($sot_cache)) {
  43. $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_Util::backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
  44. if ($result != false && PMA_DBI_num_rows($result) > 0) {
  45. while ($tmp = PMA_DBI_fetch_row($result)) {
  46. if (! isset($sot_cache[$tmp[0]])) {
  47. $sts_result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' LIKE \'' . sqlAddSlashes($tmp[0], true) . '\';');
  48. $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
  49. $tables[] = $sts_tmp;
  50. } else { // table in use
  51. $tables[] = array('Name' => $tmp[0]);
  52. }
  53. }
  54. PMA_DBI_free_result($result);
  55. $sot_ready = true;
  56. }
  57. }
  58. unset($tmp, $result);
  59. }
  60. }
  61. if (! isset($sot_ready)) {
  62. $result = PMA_DBI_query('SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ';');
  63. if (PMA_DBI_num_rows($result) > 0) {
  64. while ($sts_tmp = PMA_DBI_fetch_assoc($result)) {
  65. $tables[] = $sts_tmp;
  66. }
  67. PMA_DBI_free_result($result);
  68. unset($res);
  69. }
  70. }
  71. */
  72. /**
  73. * If there is at least one table, displays the printer friendly view, else
  74. * an error message
  75. */
  76. $tables = PMA_DBI_get_tables_full($db);
  77. $num_tables = count($tables);
  78. echo '<br />';
  79. // 1. No table
  80. if ($num_tables == 0) {
  81. echo __('No tables found in database.');
  82. } else {
  83. // 2. Shows table information
  84. ?>
  85. <table>
  86. <thead>
  87. <tr>
  88. <th><?php echo __('Table'); ?></th>
  89. <th><?php echo __('Rows'); ?></th>
  90. <th><?php echo __('Type'); ?></th>
  91. <?php
  92. if ($cfg['ShowStats']) {
  93. echo '<th>' . __('Size') . '</th>';
  94. }
  95. ?>
  96. <th><?php echo __('Comments'); ?></th>
  97. </tr>
  98. </thead>
  99. <tbody>
  100. <?php
  101. $sum_entries = $sum_size = 0;
  102. $odd_row = true;
  103. foreach ($tables as $sts_data) {
  104. if (PMA_Table::isMerge($db, $sts_data['TABLE_NAME'])
  105. || strtoupper($sts_data['ENGINE']) == 'FEDERATED'
  106. ) {
  107. $merged_size = true;
  108. } else {
  109. $merged_size = false;
  110. }
  111. $sum_entries += $sts_data['TABLE_ROWS'];
  112. ?>
  113. <tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
  114. <th>
  115. <?php echo htmlspecialchars($sts_data['TABLE_NAME']); ?>
  116. </th>
  117. <?php
  118. if (isset($sts_data['TABLE_ROWS'])) {
  119. ?>
  120. <td class="right">
  121. <?php
  122. if ($merged_size) {
  123. echo '<i>' . PMA_Util::formatNumber($sts_data['TABLE_ROWS'], 0) . '</i>' . "\n";
  124. } else {
  125. echo PMA_Util::formatNumber($sts_data['TABLE_ROWS'], 0) . "\n";
  126. }
  127. ?>
  128. </td>
  129. <td class="nowrap">
  130. <?php echo $sts_data['ENGINE']; ?>
  131. </td>
  132. <?php
  133. if ($cfg['ShowStats']) {
  134. $tblsize = $sts_data['Data_length'] + $sts_data['Index_length'];
  135. $sum_size += $tblsize;
  136. list($formated_size, $unit)
  137. = PMA_Util::formatByteDown($tblsize, 3, 1);
  138. ?>
  139. <td class="right nowrap">
  140. <?php echo $formated_size . ' ' . $unit; ?>
  141. </td>
  142. <?php
  143. } // end if
  144. } else {
  145. ?>
  146. <td colspan="3" class="center">
  147. <?php echo __('in use'); ?>
  148. </td>
  149. <?php
  150. }
  151. ?>
  152. <td>
  153. <?php
  154. if (! empty($sts_data['Comment'])) {
  155. echo htmlspecialchars($sts_data['Comment']);
  156. $needs_break = '<br />';
  157. } else {
  158. $needs_break = '';
  159. }
  160. if (! empty($sts_data['Create_time'])
  161. || ! empty($sts_data['Update_time'])
  162. || ! empty($sts_data['Check_time'])
  163. ) {
  164. echo $needs_break;
  165. ?>
  166. <table width="100%">
  167. <?php
  168. if (! empty($sts_data['Create_time'])) {
  169. ?>
  170. <tr>
  171. <td class="right"><?php echo __('Creation') . ': '; ?></td>
  172. <td class="right"><?php echo PMA_Util::localisedDate(strtotime($sts_data['Create_time'])); ?></td>
  173. </tr>
  174. <?php
  175. }
  176. if (! empty($sts_data['Update_time'])) {
  177. ?>
  178. <tr>
  179. <td class="right"><?php echo __('Last update') . ': '; ?></td>
  180. <td class="right"><?php echo PMA_Util::localisedDate(strtotime($sts_data['Update_time'])); ?></td>
  181. </tr>
  182. <?php
  183. }
  184. if (! empty($sts_data['Check_time'])) {
  185. ?>
  186. <tr>
  187. <td class="right"><?php echo __('Last check') . ': '; ?></td>
  188. <td class="right"><?php echo PMA_Util::localisedDate(strtotime($sts_data['Check_time'])); ?></td>
  189. </tr>
  190. <?php
  191. }
  192. ?>
  193. </table>
  194. <?php
  195. }
  196. ?>
  197. </td>
  198. </tr>
  199. <?php
  200. }
  201. ?>
  202. <tr>
  203. <th class="center">
  204. <?php echo sprintf(_ngettext('%s table', '%s tables', $num_tables), PMA_Util::formatNumber($num_tables, 0)); ?>
  205. </th>
  206. <th class="right nowrap">
  207. <?php echo PMA_Util::formatNumber($sum_entries, 0); ?>
  208. </th>
  209. <th class="center">
  210. --
  211. </th>
  212. <?php
  213. if ($cfg['ShowStats']) {
  214. list($sum_formated, $unit)
  215. = PMA_Util::formatByteDown($sum_size, 3, 1);
  216. ?>
  217. <th class="right nowrap">
  218. <?php echo $sum_formated . ' ' . $unit; ?>
  219. </th>
  220. <?php
  221. }
  222. ?>
  223. <th></th>
  224. </tr>
  225. </tbody>
  226. </table>
  227. <?php
  228. }
  229. /**
  230. * Displays the footer
  231. */
  232. echo PMA_Util::getButton();
  233. echo "<div id='PMA_disable_floating_menubar'></div>\n";
  234. ?>