有时候没有数据库字典设计文档,根据现有的数据库注释进行生成一份

 

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.'--数据字典

'.APPNAME.'--数据字典

(注:共'.$tab_count.'张表,按ctrl+F查找关键字)
'."\n";

for($i=0;$i<$tab_count;$i++){

echo '

    '."\n";

    echo '

  • ';

    echo ($i+1).'、表名:[' . $array[$i]['Name'] . '] 注释:' . $array[$i]['Comment'];

    echo '

  • '."\n";

    //查询数据库字段信息

    $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 '

    ';

    for($j=0;$j

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    }

    echo '

    字段 类型 为空 额外 默认 整理 备注
    ' . $tab_array[$j]['Field'] . '' . $tab_array[$j]['Type'] . '' . $tab_array[$j]['Null'] . '' . $tab_array[$j]['Extra'] . '' . $tab_array[$j]['Default'] . '' . $tab_array[$j]['Collation'] . '' . $tab_array[$j]['Comment'] . '
  • '."\n";

    echo '

  • ';

    echo '

    ';

    foreach($arr_keys as $j=>$item){

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    echo '

    '."\n";

    }

    echo '

    索引名称 索引字段 备注
    ' . $item['Key_name'] . '' . $item['Column_name'] . '' . $item['Index_type'] . '
  • '."\n";

    echo '

'."\n";

}

echo '

'."\n";

echo ''."\n";

 

效果是这样的

 

精彩文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。