您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何生成mysql数据字典

2025/3/25 18:24:11发布22次查看
把mysql数据库生成数据字典,直接可用便于查看数据库表、字段,做一个数据字典是很有必要的。本文主要为大家详细介绍了php生成mysql的数据字典的相关资料,感兴趣的小伙伴们可以参考一下。希望对大家有所帮助。
下面的代码只需要简单更改下配置就可以用了,样式也是挺好的。
<?php header('content-type:text/html;charset=utf-8'); define('db_host','localhost'); define('db_user','root'); define('db_pass','root'); define('db_name','test'); define('db_port',3306); define('db_char','utf8'); define('appname',''); $conn=mysql_connect(db_host.':'.db_port,db_user,db_pass); mysql_select_db(db_name); mysql_query('set names ' . db_char); $sql="show table status from " . db_name; $result=mysql_query($sql); $array=array(); while($rows=mysql_fetch_assoc($result)){ $array[]=$rows; } // table count $tab_count = count($array); echo '<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="zh"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>'.appname.'--数据字典</title> <style type="text/css"> table caption, table th, table td { padding: 0.1em 0.5em 0.1em 0.5em; margin: 0.1em; vertical-align: top; } th { font-weight: bold; color: black; background: #d3dce3; } table tr.odd th, .odd { background: #e5e5e5; } table tr.even th, .even { background: #f3f3f3; } .db_table{ border-top:1px solid #333; } .title{font-weight:bold;} </style> </head> <body> <p style="text-align:center;background:#d3dce3;font-size:19px;"> <b>'.appname.'--数据字典</b> </p> <p style="background:#f3f3f3;text-align:center;">(注:共'.$tab_count.'张表,按ctrl+f查找关键字)</p>'."\n"; for($i=0;$i<$tab_count;$i++){ echo '<ul type="square">'."\n"; echo ' <li class="title">'; echo ($i+1).'、表名:[' . $array[$i]['name'] . '] 注释:' . $array[$i]['comment']; echo '</li>'."\n"; //查询数据库字段信息 $tab_name = $array[$i]['name']; $sql_tab='show full fields from `' . $array[$i]['name'].'`'; $tab_result=mysql_query($sql_tab); $tab_array=array(); while($r=mysql_fetch_assoc($tab_result)){ $tab_array[]=$r; } //show keys $keys_result=mysql_query("show keys from `".$array[$i]['name'].'`',$conn); $arr_keys=mysql_fetch_array($keys_result); echo '<li style="list-style: none outside none;"><table border="0" class="db_table" >'; echo '<tr class="head"> <th style="width:110px">字段</th> <th>类型</th> <th>为空</th> <th>额外</th> <th>默认</th> <th style="width:95px">整理</th> <th>备注</th></tr>'; for($j=0;$j<count($tab_array);$j++){ $key_name=$arr_keys['key_name']; if($key_name="primary"){ $key_name='主键('.$key_name.')'; } $key_field=$arr_keys['column_name']; if ( $tab_array[$j]['field']==$key_field){ $key_value="pk"; }else{ $key_value=""; } echo ' <tr class="'.($j%2==0?"odd":"even").'">'."\n"; echo ' <td>' . $tab_array[$j]['field'] . '</td>'."\n"; echo ' <td>' . $tab_array[$j]['type'] . '</td>'."\n"; echo ' <td>' . ($key_value!=''?$key_value:$tab_array[$j]['null']) . '</td>'."\n"; echo ' <td>' . $tab_array[$j]['extra'] . '</td>'."\n"; echo ' <td>' . $tab_array[$j]['default'] . '</td>'."\n"; echo ' <td>' . $tab_array[$j]['collation'] . '</td>'."\n"; echo ' <td>' . ($key_value!=''?$key_name:$tab_array[$j]['comment']) . '</td>'."\n"; echo ' </tr>'."\n"; } echo ' </table></li>'."\n"; echo '</ul>'."\n"; } echo '</body>'."\n"; echo '</html>'."\n";
相关推荐:
php mysql pdo 查询操作实例介绍
php mysqli扩展之预处理实例详解
php mysql连接专题:最全的php连接mysql数据库教程总结
以上就是php如何生成mysql数据字典的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product