show(); class MakeDBDocument { var $dsql; function __construct() { global $dsql; $this->dsql = $dsql; } //分析具体表 function analyse_table(&$tableinfo, $tablename) { $flines = explode("\n", $tableinfo); $addinfo = $tbinfo = $tb_comment = ''; $fields = array(); foreach($flines as $line) { $line = trim($line); if( $line=='' ) continue; if( preg_match('/CREATE TABLE/i', $line) ) continue; if( !preg_match('/`/', $line) ) { $arr = ''; preg_match("/ENGINE=([a-z]*)(.*)DEFAULT CHARSET=([a-z0-9]*)/i", $line, $arr); $tbinfo = "ENGINE=".$arr[1].'/CHARSET='.$arr[3]; $arr = ''; preg_match("/comment='([^']*)'/i", $line, $arr); if( isset($arr[1]) ) { $tb_comment = $arr[1]; } continue; } if( preg_match('/KEY/', $line) ) { $addinfo .= $line."
\n"; } else { $arr = ''; $nline = preg_replace("/comment '([^']*)'/i", '', $line); preg_match("/`([^`]*)` (.*)[,]{0,1}$/U", $nline, $arr); $f = $arr[1]; $fields[ $f ][0] = $arr[2]; $fields[ $f ][1] = ''; $arr = ''; preg_match("/comment '([^']*)'/i", $line, $arr); if( isset($arr[1]) ) { $fields[ $f ][1] = $arr[1]; } } } $tablehtml = " \n"; foreach($fields as $k=>$v) { $tablehtml .= " \n"; } $tablehtml .= "
表名:{$tablename}
($tbinfo)
说明:{$tb_comment}
字段名 说明描述 具体参数
{$k} {$v[1]} {$v[0]}
索引:
{$addinfo}
"; return $tablehtml; } //列出数据库的所有表 function show( $type='' ) { global $cfg_soft_lang; $namehtml = $tablehtml = ''; $this->dsql->Execute('me', ' SHOW TABLES; '); if (version_compare(PHP_VERSION, '7.0.0', '>=')) { define("MYSQL_NUM", MYSQLI_NUM); } while( $row = $this->dsql->GetArray('me', MYSQL_NUM) ) { $this->dsql->Execute('dd', " Show CREATE TABLE `{$row[0]}` "); $row2 = $this->dsql->GetArray('dd', MYSQL_NUM); if( $type=='' ) { if( preg_match("/^cms_/", $row[0]) ) continue; } else { if( !preg_match("/^".$type."_/", $row[0]) ) continue; } $namehtml .= "{$row[0]} | "; $tablehtml .= $this->analyse_table( $row2[1], $row[0]); } $htmlhead = " 数据库说明文档 "; echo $htmlhead; echo "
".$namehtml."
"; echo $tablehtml; echo "\n"; exit(); }//end show }