php mysql 数据字典_php如何生成mysql数据字典
把mysql數(shù)據(jù)庫生成數(shù)據(jù)字典,直接可用便于查看數(shù)據(jù)庫表、字段,做一個數(shù)據(jù)字典是很有必要的。本文主要為大家詳細介紹了php生成mysql的數(shù)據(jù)字典的相關(guān)資料,感興趣的小伙伴們可以參考一下。希望對大家有所幫助。
下面的代碼只需要簡單更改下配置就可以用了,樣式也是挺好的。<?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 '/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
'.APPNAME.'--數(shù)據(jù)字典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;}
'.APPNAME.'--數(shù)據(jù)字典
(注:共'.$tab_count.'張表,按ctrl+F查找關(guān)鍵字)
'."\n";for($i=0;$i
echo '
- '."\n";
echo '
';echo ($i+1).'、表名:[' . $array[$i]['Name'] . '] 注釋:' . $array[$i]['Comment'];
echo '
'."\n";//查詢數(shù)據(jù)庫字段信息
$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 '
echo '
字段類型為空額外默認整理備注';for($j=0;$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 '
'."\n";echo '
' . $tab_array[$j]['Field'] . ''."\n";echo '
' . $tab_array[$j]['Type'] . ''."\n";echo '
' . ($key_value!=''?$key_value:$tab_array[$j]['Null']) . ''."\n";echo '
' . $tab_array[$j]['Extra'] . ''."\n";echo '
' . $tab_array[$j]['Default'] . ''."\n";echo '
' . $tab_array[$j]['Collation'] . ''."\n";echo '
' . ($key_value!=''?$key_name:$tab_array[$j]['Comment']) . ''."\n";echo '
'."\n";}
echo '
'."\n";echo '
'."\n";}
echo ''."\n";
echo ''."\n";
相關(guān)推薦:
總結(jié)
以上是生活随笔為你收集整理的php mysql 数据字典_php如何生成mysql数据字典的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 润和软件2021发展前景 受鸿蒙利
- 下一篇: linux cmake编译源码,linu