tbl_info.inc.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * extracts table properties from create statement
  5. *
  6. * @todo should be handled by class Table
  7. * @todo this should be recoded as functions, to avoid messing with global variables
  8. *
  9. * @package PhpMyAdmin
  10. */
  11. if (! defined('PHPMYADMIN')) {
  12. exit;
  13. }
  14. // Check parameters
  15. PMA_Util::checkParameters(array('db', 'table'));
  16. /**
  17. * Defining global variables, in case this script is included by a function.
  18. */
  19. global $showtable, $tbl_is_view, $tbl_storage_engine, $show_comment, $tbl_collation,
  20. $table_info_num_rows, $auto_increment;
  21. /**
  22. * Gets table informations
  23. */
  24. // Seems we need to do this in MySQL 5.0.2,
  25. // otherwise error #1046, no database selected
  26. $GLOBALS['dbi']->selectDb($GLOBALS['db']);
  27. /**
  28. * Holds information about the current table
  29. *
  30. * @todo replace this by PMA_Table
  31. * @global array $GLOBALS['showtable']
  32. * @name $showtable
  33. */
  34. $GLOBALS['showtable'] = array();
  35. // PMA_Table::sGetStatusInfo() does caching by default, but here
  36. // we force reading of the current table status
  37. // if $reread_info is true (for example, coming from tbl_operations.php
  38. // and we just changed the table's storage engine)
  39. $GLOBALS['showtable'] = PMA_Table::sGetStatusInfo(
  40. $GLOBALS['db'],
  41. $GLOBALS['table'],
  42. null,
  43. (isset($reread_info) && $reread_info ? true : false)
  44. );
  45. // need this test because when we are creating a table, we get 0 rows
  46. // from the SHOW TABLE query
  47. // and we don't want to mess up the $tbl_storage_engine coming from the form
  48. if ($showtable) {
  49. if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
  50. $tbl_is_view = true;
  51. $tbl_storage_engine = __('View');
  52. $show_comment = null;
  53. } else {
  54. $tbl_is_view = false;
  55. $tbl_storage_engine = isset($showtable['Engine'])
  56. ? strtoupper($showtable['Engine'])
  57. : '';
  58. $show_comment = '';
  59. if (isset($showtable['Comment'])) {
  60. $show_comment = $showtable['Comment'];
  61. }
  62. }
  63. $tbl_collation = empty($showtable['Collation'])
  64. ? ''
  65. : $showtable['Collation'];
  66. if (null === $showtable['Rows']) {
  67. $showtable['Rows'] = PMA_Table::countRecords(
  68. $GLOBALS['db'], $showtable['Name'], true
  69. );
  70. }
  71. $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
  72. $row_format = isset($showtable['Row_format']) ? $showtable['Row_format'] : '';
  73. $auto_increment = isset($showtable['Auto_increment'])
  74. ? $showtable['Auto_increment']
  75. : '';
  76. $create_options = isset($showtable['Create_options'])
  77. ? explode(' ', $showtable['Create_options'])
  78. : array();
  79. // export create options by its name as variables into global namespace
  80. // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
  81. unset($pack_keys);
  82. foreach ($create_options as $each_create_option) {
  83. $each_create_option = explode('=', $each_create_option);
  84. if (isset($each_create_option[1])) {
  85. $$each_create_option[0] = $each_create_option[1];
  86. }
  87. }
  88. // we need explicit DEFAULT value here (different from '0')
  89. $pack_keys = (! isset($pack_keys) || strlen($pack_keys) == 0)
  90. ? 'DEFAULT'
  91. : $pack_keys;
  92. unset($create_options, $each_create_option);
  93. } // end if
  94. ?>