<?PHPHeader(' Content-type:text/html;charset=utf-8 '); Define(' db_host ', ' localhost '); Define(' Db_user ', ' root '); Define(' Db_pass ', '); Define(' db_name ', ' MSSC '); 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 "> ‘. APPNAME. '--Data dictionary </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> ‘. APPNAME. '--Data dictionary </b> </div> <div style= "background: #f3f3f3; text-align:center;" > (Note: Total‘.$tab _count.‘ List, press Ctrl+f to find keywords) </div> '. ' \ n "; for($i= 0;$i<$tab _count;$i++){ Echo' <ul type= ' square ' > '. ' \ n "; Echo' <li class= ' title ' > '; Echo($i+1). ', table name: ['.$array[$i[' Name ']. '] Note: '.$array[$i[' Comment ']; Echo' </li> '. \ n "; //Querying database field information$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" > Fields </th> <th> type </th> <th> null </th> <th> additional </th> <th> default </th> <th style= "width:95 px > Finishing </th> <th> remarks </th></tr>‘; for($j= 0;$j<Count($tab _array);$j++){ $key _name=$arr _keys[' Key_name ']; if($key _name= "PRIMARY"){ $key _name= ' primary key ('.$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' Effect:
PHP data dictionary for MySQL generation