Because the project development uses the more table, in order to obtain the data dictionary quickly, obtains the table structure and the table annotation through the PHP code way. The code is as follows:
<?PHP/** * Generate MySQL data dictionary*/Header("content-type:text/html; Charset=utf-8 " );//Configuration Database$dbserver= "localhost";$dbusername= "Database user name";$dbpassword= "Database Password";$database= "Database Name";//Other Configurations$title= ' Data dictionary ';$mysql _conn= @mysql_connect( "$dbserver", "$dbusername", "$dbpassword") or die("Mysql Connect is error.") );mysql_select_db($database,$mysql _conn );mysql_query(' SET NAMES UTF8 ',$mysql _conn );$table _result=mysql_query(' Show Tables ',$mysql _conn );//get all the table names while($row=Mysql_fetch_array($table _result ) ) { $tables[] [' table_name '] =$row[0];}//Loop to get notes for all tables and column messages in the tableforeach($tables as $k=$v ) { $sql= ' SELECT * from '; $sql. = ' Information_schema. TABLES '; $sql. = ' WHERE '; $sql. = "table_name = ' {$v[' table_name ']} ' and Table_schema = ' {$database}‘"; $table _result=mysql_query($sql,$mysql _conn ); while($t=Mysql_fetch_array($table _result ) ) { $tables[$k] [' table_comment '] =$t[' Table_comment ']; } $sql= ' SELECT * from '; $sql. = ' Information_schema. COLUMNS '; $sql. = ' WHERE '; $sql. = "table_name = ' {$v[' table_name ']} ' and Table_schema = ' {$database}‘"; $fields=Array (); $field _result=mysql_query($sql,$mysql _conn ); while($t=Mysql_fetch_array($field _result ) ) { $fields[] =$t; } $tables[$k] [' COLUMN '] =$fields;}Mysql_close($mysql _conn );$html= ' ';//Loop All Tablesforeach($tables as $k=$v ) { //$html. = ' <p> $html. = ' <table border= ' 1 "cellspacing=" 0 "cellpadding=" 0 "align=" center "> '; $html. = ' <caption> '.$v[' table_name ']. ‘ ‘ .$v[' Table_comment ']. ' </caption> '; $html=<tbody><tr><th> Field name </th><th> data type </th><th> default </th> <th> Allow non-empty </th> <th> auto increment </th><th> remarks </th></tr>‘; $html. = '; foreach($v[' COLUMN '] as $f ) { $html. = ' <tr><td class= ' C1 ' > '.$f[' column_name ']. ' </td> '; $html. = ' <td class= ' C2 ' > '.$f[' Column_type ']. ' </td> '; $html. = ' <td class= ' C3 ' > '.$f[' Column_default ']. ' </td> '; $html. = ' <td class= ' C4 ' > '.$f[' is_nullable ']. ' </td> '; $html. = ' <TD class= ' c5 ' > '. ($f[' EXTRA '] = = ' auto_increment '? ' Yes ': ' ') . ' </td> '; $html. = ' <td class= ' c6 ' > '.$f[' Column_comment ']. ' </td> '; $html. = ' </tr> '; } $html. = ' </tbody></table></p> ';}//OutputEcho‘‘ .$title. ‘</title><style>body,td,th {font-family: "Song body"; font-size:12px;} table{border-collapse:collapse;border:1px solid #CCC; background: #6089D4;} Table caption{text-align:left; Background-color: #fff; line-height:2em; font-size:14px; font-weight:bold;} Table th{text-align:left; font-weight:bold;height:26px; line-height:25px; font-size:16px; border:3px solid #fff; color : #ffffff; padding:5px;} Table td{height:25px; font-size:12px; border:3px solid #fff; Background-color: #f0f0f0; padding:5px;}. c1{width:150px;}. c2{width:130px;}. c3{width:70px;}. c4{width:80px;}. c5{width:80px;}. c6{width:300px;} </style>‘;Echo' $title. ' ;Echo $html;Echo' </body>;?>
PHP generates MySQL data dictionary code