有时候没有数据库字典设计文档,根据现有的数据库注释进行生成一份
header('content-type:text/html;charset=utf-8');
define('DB_HOST','192.168.11.7');
define('DB_USER','root');
define('DB_PASS','centos');
define('DB_NAME','new_admin');
define('DB_PORT',3306);
define('DB_CHAR','utf8');
define('APPNAME','new_admin');
$dbh = new PDO("mysql:host=".DB_HOST.":".DB_PORT.";dbname=".DB_NAME,DB_USER,DB_PASS);
$dbh->exec('set names ' . DB_CHAR);
$sth = $dbh->prepare("SHOW TABLE STATUS FROM " . DB_NAME);
$sth->execute();
$array = $sth->fetchAll(PDO::FETCH_ASSOC);
$tab_count = count($array);
echo '
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
'.APPNAME.'--数据字典
for($i=0;$i<$tab_count;$i++){
echo '
- '."\n";
- ';
echo ($i+1).'、表名:[' . $array[$i]['Name'] . '] 注释:' . $array[$i]['Comment'];
echo '
'."\n"; ';
echo '
字段 类型 为空 额外 默认 整理 备注 for($j=0;$j
echo '
'."\n"; '."\n";echo '
' . $tab_array[$j]['Field'] . ' '."\n";echo '
' . $tab_array[$j]['Type'] . ' '."\n";echo '
' . $tab_array[$j]['Null'] . ' '."\n";echo '
' . $tab_array[$j]['Extra'] . ' '."\n";echo '
' . $tab_array[$j]['Default'] . ' '."\n";echo '
' . $tab_array[$j]['Collation'] . ' '."\n";echo '
' . $tab_array[$j]['Comment'] . ' '."\n";echo '
}
echo '
'."\n";';
echo '
索引名称 索引字段 备注 foreach($arr_keys as $j=>$item){
echo '
'."\n"; '."\n";echo '
' . $item['Key_name'] . ' '."\n";echo '
' . $item['Column_name'] . ' '."\n";echo '
' . $item['Index_type'] . ' '."\n";echo '
}
echo '
'."\n";
echo '
//查询数据库字段信息
$tab_name = $array[$i]['Name'];
$sql_tab='show full fields from `' . $array[$i]['Name'].'`';
$sth = $dbh->prepare($sql_tab);
$sth->execute();
$tab_array = $sth->fetchAll(PDO::FETCH_ASSOC);
//show keys
$sth = $dbh->prepare("show keys from `".$array[$i]['Name'].'`');
$sth->execute();
$arr_keys = $sth->fetchAll(PDO::FETCH_ASSOC);
echo '
echo '
echo '
}
echo '
'."\n";echo ''."\n";
效果是这样的
精彩文章
发表评论