<?PHPHeader("content-type:text/html; Charset=utf-8 "); $dbserver= "localhost"; $dbusername= "Root"; $dbpassword= "Root"; $title= ' Data dictionary '; if($_get[' db '] = = '){ $database= "AA"; }Else{ $database=$_get[' DB ']; } $mysql _conn= @mysql_connect("{$dbserver}","{$dbusername}","{$dbpassword} ") or die("Mysql Connect is error.")); mysql_select_db($database,$mysql _conn); $result=mysql_query(' Show Tables ',$mysql _conn); mysql_query(' SET NAMES UTF8 ',$mysql _conn); //get all table names while($row=Mysql_fetch_array($result)){ $tables[] [' table_name '] =$row[0]; } //Loop to get notes for all tables and column messages in the table foreach($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 Tables foreach($tables as $k=$v){ $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 value </th><th> Allow non-null </th><th> auto increment </th><th> comment </th></tr> '; $html. = '; foreach($v[' COLUMN '] as $f){ $html. = ' <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 '? ' Is ': '). ' </td> '; $html. = ' <td class= ' C6 ' > '.$f[' Column_comment ']. ' </td> '; $html. = ' </tr> '; } $html. = ' </tbody></table></p> '; } Echo‘‘; Echo' $title.‘ ; Echo $html; Echo' </body>;?>
Generate a data dictionary in PHP