国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

152 lines
5.1KB

  1. <?php
  2. /**
  3. * 数据表信息查看
  4. *
  5. * @version $Id: sys_sql_info.php 1 22:28 2010年7月20日Z tianya $
  6. * @package DedeCMS.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require(dirname(__FILE__)."/config.php");
  12. CheckPurview('sys_Data');
  13. if(empty($dopost)) $dopost = "";
  14. $dbdoc = new MakeDBDocument;
  15. $dbdoc->show();
  16. class MakeDBDocument
  17. {
  18. var $dsql;
  19. function __construct()
  20. {
  21. global $dsql;
  22. $this->dsql = $dsql;
  23. }
  24. //分析具体表
  25. function analyse_table(&$tableinfo, $tablename)
  26. {
  27. $flines = explode("\n", $tableinfo);
  28. $addinfo = $tbinfo = $tb_comment = '';
  29. $fields = array();
  30. foreach($flines as $line)
  31. {
  32. $line = trim($line);
  33. if( $line=='' ) continue;
  34. if( preg_match('/CREATE TABLE/i', $line) ) continue;
  35. if( !preg_match('/`/', $line) )
  36. {
  37. $arr = '';
  38. preg_match("/ENGINE=([a-z]*)(.*)DEFAULT CHARSET=([a-z0-9]*)/i", $line, $arr);
  39. $tbinfo = "ENGINE=".$arr[1].'/CHARSET='.$arr[3];
  40. $arr = '';
  41. preg_match("/comment='([^']*)'/i", $line, $arr);
  42. if( isset($arr[1]) )
  43. {
  44. $tb_comment = $arr[1];
  45. }
  46. continue;
  47. }
  48. if( preg_match('/KEY/', $line) )
  49. {
  50. $addinfo .= $line."<br />\n";
  51. }
  52. else
  53. {
  54. $arr = '';
  55. $nline = preg_replace("/comment '([^']*)'/i", '', $line);
  56. preg_match("/`([^`]*)` (.*)[,]{0,1}$/U", $nline, $arr);
  57. $f = $arr[1];
  58. $fields[ $f ][0] = $arr[2];
  59. $fields[ $f ][1] = '';
  60. $arr = '';
  61. preg_match("/comment '([^']*)'/i", $line, $arr);
  62. if( isset($arr[1]) )
  63. {
  64. $fields[ $f ][1] = $arr[1];
  65. }
  66. }
  67. }
  68. $tablehtml = " <table width=\"960\" align=\"center\" border=\"0\" cellpadding=\"5\" cellspacing=\"1\" bgcolor=\"#C1D1A3\" style=\"font-size:14px;margin-bottom:10px\">
  69. <tr>
  70. <td height=\"34\" colspan=\"3\" bgcolor=\"#DDEDA5\">
  71. <a name=\"{$tablename}\"></a>
  72. <table width=\"90%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\">
  73. <tr>
  74. <td width=\"29%\"><strong>表名:{$tablename}</strong> <br />($tbinfo)</td>
  75. <td width=\"71%\">说明:{$tb_comment}</td>
  76. </tr>
  77. </table></td>
  78. </tr>
  79. <tr>
  80. <td width=\"20%\" height=\"28\" bgcolor=\"#F7FDEA\">字段名</td>
  81. <td width=\"28%\" bgcolor=\"#F7FDEA\">说明描述</td>
  82. <td bgcolor=\"#F7FDEA\">具体参数</td>
  83. </tr>\n";
  84. foreach($fields as $k=>$v)
  85. {
  86. $tablehtml .= " <tr height=\"24\" bgcolor=\"#FFFFFF\">
  87. <td><b>{$k}</b></td>
  88. <td>{$v[1]}</td>
  89. <td>{$v[0]}</td>
  90. </tr>\n";
  91. }
  92. $tablehtml .= " <tr>
  93. <td height=\"28\" colspan=\"3\" bgcolor=\"#F7FDEA\">
  94. <b>索引:</b><br />
  95. {$addinfo}
  96. </td>
  97. </tr>
  98. </table>";
  99. return $tablehtml;
  100. }
  101. //列出数据库的所有表
  102. function show( $type='' )
  103. {
  104. global $cfg_soft_lang;
  105. $namehtml = $tablehtml = '';
  106. $this->dsql->Execute('me', ' SHOW TABLES; ');
  107. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  108. define("MYSQL_NUM", MYSQLI_NUM);
  109. }
  110. while( $row = $this->dsql->GetArray('me', MYSQL_NUM) )
  111. {
  112. $this->dsql->Execute('dd', " Show CREATE TABLE `{$row[0]}` ");
  113. $row2 = $this->dsql->GetArray('dd', MYSQL_NUM);
  114. if( $type=='' )
  115. {
  116. if( preg_match("/^cms_/", $row[0]) ) continue;
  117. }
  118. else
  119. {
  120. if( !preg_match("/^".$type."_/", $row[0]) ) continue;
  121. }
  122. $namehtml .= "<a href='#{$row[0]}'>{$row[0]}</a> | ";
  123. $tablehtml .= $this->analyse_table( $row2[1], $row[0]);
  124. }
  125. $htmlhead = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
  126. <html xmlns=\"http://www.w3.org/1999/xhtml\">
  127. <head>
  128. <meta http-equiv=\"Content-Type\" content=\"text/html; charset={$cfg_soft_lang}\" />
  129. <link href=\"css/base.css\" rel=\"stylesheet\" type=\"text/css\">
  130. <style>
  131. * {
  132. font-size:14px;
  133. font-family:Arial, \"宋休\", \"Courier New\";
  134. }
  135. a {
  136. text-decoration:none;
  137. }
  138. </style>
  139. <title>数据库说明文档</title>
  140. </head>
  141. <body background='images/allbg.gif' leftmargin='8' topmargin='8'>";
  142. echo $htmlhead;
  143. echo "<table align='center' width='960' style='margin-bottom:8px' ><tr><td>".$namehtml."</td></tr></table>";
  144. echo $tablehtml;
  145. echo "</body>\n</html>";
  146. exit();
  147. }//end show
  148. }