<?php
Header ("Content-type=text/html;charset=utf-8");
$link = mysql_connect (' localhost ', ' root ', ');
if (! $link) {
Die (' Could not connect: '. Mysql_error ());
}
mysql_select_db ("Qujiang", $link) or Die (' can\ ' t use foo: '. mysql_error ());
mysql_query ("Set names ' UTF8 '", $link);
$info = mysql_query ("Select table_name tables,table_comment COMMENT from INFORMATION_SCHEMA. TABLES WHERE table_schema = ' Qujiang ' ", $link) or Die (" Invalid query: ". Mysql_error ());
$i = 0;
while ($arr = Mysql_fetch_assoc ($info)) {
$data [$i] = array (' tables ' + = $arr [' Tables '], ' comment ' = $arr [' comment ']);
$field _data = Array ();
$DQL = ' show full fields from Qujiang. '. $arr [' Tables ']. ' '
$field _info = mysql_query ($DQL);
while ($fieldarr = Mysql_fetch_assoc ($field _info)) {
$field _data[] = $fieldarr;
}
$comment = $arr [' comment ']? ' ('. $arr [' comment ']. ') ': ';
$data [$i] [' table '] = $arr [' Tables ']. $comment;
$data [$i] [' fields '] = $field _data;
$i + +;
}//print_r ($data);
Mysql_close ($link);
?>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<style type= "Text/css" >
Table {
border:1px solid #B1CDE3;
padding:0;
margin:0 Auto;
Border-collapse:collapse;
}
TD {
border:1px solid #B1CDE3;
Background: #fff;
font-size:12px;
padding:3px 3px 3px 8px;
Color: #4f6b72;
}
. s{
Background: #def;
font-size:13px;
}
</style>
<body>
<?php foreach ($data as $keys = = $vo) {?>
<div style= "height:40px; line-height:40px; " ><?php echo $vo [' table '];? ></div>
<table width= "100%" align= "Center" >
<tr style= "Text-align:center; COLOR: #0076C8; Background-color: #CCC; height:35px; Font-weight:bold ">
<TD class= "s" > Field name </td>
<TD class= "S" > Type </td>
<TD class= "S" >Null</td>
<TD class= "S" >Key</td>
<TD class= "S" >Default</td>
<TD class= "S" >Extra</td>
<TD class= "s" > Description </td>
</tr>
<?php foreach ($vo [' Fields '] as $k = + $vf) {?>
<tr>
<TD nowrap= "nowrap" align= "left" ><?php echo $vf [' Field '];? ></td>
<TD align= "left" ><font size= "2" ><?php echo $vf [' Type '];? ></font></td>
<TD align= "left" ><font size= "2" ><?php echo $vf [' Null '];? ></font></td>
<TD align= "left" ><font size= "2" ><?php echo $vf [' Key '];? ></font></td>
<TD align= "left" ><font size= "2" ><?php echo $vf [' Default '];? ></font></td>
<TD align= "left" ><font size= "2" ><?php echo $vf [' Extra '];? ></font></td>
<TD align= "left" ><font size= "2" ><?php echo $vf [' Comment '];? ></font></td>
</tr>
<?php}?>
</table>
<?php}?>
</body>
This article from the "PHP Engineer Blog" blog, declined to reprint!
Read table structure, generate table document