/phpmyadmin/libraries/tbl_info.inc.php

https://github.com/md-tech/openemr · PHP · 111 lines · 62 code · 13 blank · 36 comment · 14 complexity · 1cf04cb4c1de67c51af2fb0313fb42c9 MD5 · raw file

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @version $Id$
  6. */
  7. if (! defined('PHPMYADMIN')) {
  8. exit;
  9. }
  10. /**
  11. *
  12. */
  13. require_once './libraries/Table.class.php';
  14. /**
  15. * extracts table properties from create statement
  16. *
  17. * @todo this should be recoded as functions,
  18. * to avoid messing with global variables
  19. */
  20. /**
  21. * requirements
  22. */
  23. require_once './libraries/common.inc.php';
  24. // Check parameters
  25. PMA_checkParameters(array('db', 'table'));
  26. /**
  27. * Defining global variables, in case this script is included by a function.
  28. * This is necessary because this script can be included by libraries/header.inc.php.
  29. */
  30. global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
  31. $table_info_num_rows, $auto_increment;
  32. /**
  33. * Gets table informations
  34. */
  35. // Seems we need to do this in MySQL 5.0.2,
  36. // otherwise error #1046, no database selected
  37. PMA_DBI_select_db($GLOBALS['db']);
  38. // The 'show table' statement works correct since 3.23.03
  39. $table_info_result = PMA_DBI_query(
  40. 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
  41. null, PMA_DBI_QUERY_STORE);
  42. // need this test because when we are creating a table, we get 0 rows
  43. // from the SHOW TABLE query
  44. // and we don't want to mess up the $tbl_type coming from the form
  45. if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
  46. $showtable = PMA_DBI_fetch_assoc($table_info_result);
  47. PMA_DBI_free_result($table_info_result);
  48. unset($table_info_result);
  49. if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
  50. $showtable['Type'] =& $showtable['Engine'];
  51. }
  52. if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
  53. $tbl_is_view = true;
  54. $tbl_type = $GLOBALS['strView'];
  55. $show_comment = null;
  56. } else {
  57. $tbl_is_view = false;
  58. $tbl_type = isset($showtable['Type'])
  59. ? strtoupper($showtable['Type'])
  60. : '';
  61. // a new comment could be coming from tbl_operations.php
  62. // and we want to show it in the header
  63. if (isset($submitcomment) && isset($comment)) {
  64. $show_comment = $comment;
  65. } else {
  66. $show_comment = isset($showtable['Comment'])
  67. ? $showtable['Comment']
  68. : '';
  69. }
  70. }
  71. $tbl_collation = empty($showtable['Collation'])
  72. ? ''
  73. : $showtable['Collation'];
  74. if (null === $showtable['Rows']) {
  75. $showtable['Rows'] = PMA_Table::countRecords($GLOBALS['db'],
  76. $showtable['Name'], true, true);
  77. }
  78. $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
  79. $auto_increment = isset($showtable['Auto_increment'])
  80. ? $showtable['Auto_increment']
  81. : '';
  82. $create_options = isset($showtable['Create_options'])
  83. ? explode(' ', $showtable['Create_options'])
  84. : array();
  85. // export create options by its name as variables into gloabel namespace
  86. // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
  87. unset($pack_keys);
  88. foreach ($create_options as $each_create_option) {
  89. $each_create_option = explode('=', $each_create_option);
  90. if (isset($each_create_option[1])) {
  91. $$each_create_option[0] = $each_create_option[1];
  92. }
  93. }
  94. // we need explicit DEFAULT value here (different from '0')
  95. $pack_keys = (!isset($pack_keys) || strlen($pack_keys) == 0) ? 'DEFAULT' : $pack_keys;
  96. unset($create_options, $each_create_option);
  97. } // end if
  98. ?>