經常為了方便和直觀,我們會首先直接在數據庫中設計出表,但是接下來又要將表的結構和設計編寫在設計文檔中,以便編碼的時候可以直觀的查詢,一旦數據庫表非常多,字段非常多的時候,這無疑是件非常郁悶的工作。
這是一個漂亮的PHP頁面,可以自動輸出MySql數據庫所有表結構,大大方便了文檔的編寫工作,也同時非常方便編碼的時候進行查詢。當然在設計MySql數據庫表和字段的時候詳細填寫表和字段的備注,這是非常好的習慣,對這個網頁的輸出也是最佳效果的。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< style type ="text/css" >
<!--
body,table{
font-size:13px;
}
table{
table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
margin:0 auto;
border:1px solid #cad9ea;
}
th{
height:22px;
font-size:13px;
font-weight:bold;
text-align:center;
}
td{
height:20px;
}
.tableTitle{font-size:14px; font-weight:bold;}
</style>
< title >zuizen數據庫結構 </title>
</head>
< body >
< div style ="margin:0 auto;width:880px; border:1px #006600 solid; font-size:12px; line-height:20px;" >
< div style ="width:100%;height:30px; font-size:16px; font-weight:bold; text-align:center;" >
**網數據庫結構 < br />
< font style ="font-size:14px; font-weight:normal;" > < ?php echo date("Y-m-d h:i:s"); ? > </font>
</div>
<?php
$dbconn=mysql_connect("localhost", "root","123");
$sqlname="information_schema";
mysql_select_db($sqlname,$dbconn);
session_start();
$sql = "SELECT * FROM tables where table_schema='db_zuizen' order by TABLE_NAME";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result))
{
//print_r($row);
?>
< div style ="margin:0 auto; width:100%; padding-top:10px;" >
< b class ="tableTitle" >表名: < ?php echo $row["TABLE_NAME"] ? > </b> < br />
< ?php echo $row["TABLE_COMMENT"] ? >
</div>
< table width ="100%" border ="1" >
< thead >
< th width ="70" >序號 </td>
< th width ="170" >字段名 </td>
< th width ="140" >字段類型 </td>
< th width ="80" >允許為空 </td>
< th width ="70" >默認值 </td>
< th >備注 </td>
</thead>
<?php
$sql2 = "SELECT * FROM columns where table_name='".$row["TABLE_NAME"]."' order by COLUMN_NAME";
$result2 = mysql_query($sql2);
$num=0;
while($row2=mysql_fetch_array($result2))
{
$num = $num+1;
//print_r($row);
?>
< tr >
< td align ="center" > < b > < ?php echo $num ? > </b> </td>
< td > < ?php echo $row2["COLUMN_NAME"] ? > </td>
< td > < ?php echo $row2["COLUMN_TYPE"] ? > </td>
< td align ="center" > < ?php echo $row2["IS_NULLABLE"] ? > </td>
< td align ="center" > < ?php echo $row2["COLUMN_DEFAULT"] ? > </td>
< td > < ?php echo $row2["COLUMN_COMMENT"] ? > </td>
</tr>
<?php
}
?>
</table>
<?php
}
mysql_close($dbconn);
?>
</div>
</body>
</html>
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" />
< style type ="text/css" >
<!--
body,table{
font-size:13px;
}
table{
table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
margin:0 auto;
border:1px solid #cad9ea;
}
th{
height:22px;
font-size:13px;
font-weight:bold;
text-align:center;
}
td{
height:20px;
}
.tableTitle{font-size:14px; font-weight:bold;}
</style>
< title >zuizen數據庫結構 </title>
</head>
< body >
< div style ="margin:0 auto;width:880px; border:1px #006600 solid; font-size:12px; line-height:20px;" >
< div style ="width:100%;height:30px; font-size:16px; font-weight:bold; text-align:center;" >
**網數據庫結構 < br />
< font style ="font-size:14px; font-weight:normal;" > < ?php echo date("Y-m-d h:i:s"); ? > </font>
</div>
<?php
$dbconn=mysql_connect("localhost", "root","123");
$sqlname="information_schema";
mysql_select_db($sqlname,$dbconn);
session_start();
$sql = "SELECT * FROM tables where table_schema='db_zuizen' order by TABLE_NAME";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result))
{
//print_r($row);
?>
< div style ="margin:0 auto; width:100%; padding-top:10px;" >
< b class ="tableTitle" >表名: < ?php echo $row["TABLE_NAME"] ? > </b> < br />
< ?php echo $row["TABLE_COMMENT"] ? >
</div>
< table width ="100%" border ="1" >
< thead >
< th width ="70" >序號 </td>
< th width ="170" >字段名 </td>
< th width ="140" >字段類型 </td>
< th width ="80" >允許為空 </td>
< th width ="70" >默認值 </td>
< th >備注 </td>
</thead>
<?php
$sql2 = "SELECT * FROM columns where table_name='".$row["TABLE_NAME"]."' order by COLUMN_NAME";
$result2 = mysql_query($sql2);
$num=0;
while($row2=mysql_fetch_array($result2))
{
$num = $num+1;
//print_r($row);
?>
< tr >
< td align ="center" > < b > < ?php echo $num ? > </b> </td>
< td > < ?php echo $row2["COLUMN_NAME"] ? > </td>
< td > < ?php echo $row2["COLUMN_TYPE"] ? > </td>
< td align ="center" > < ?php echo $row2["IS_NULLABLE"] ? > </td>
< td align ="center" > < ?php echo $row2["COLUMN_DEFAULT"] ? > </td>
< td > < ?php echo $row2["COLUMN_COMMENT"] ? > </td>
</tr>
<?php
}
?>
</table>
<?php
}
mysql_close($dbconn);
?>
</div>
</body>
</html>
以下為運行抓取的樣子:
轉自:http://blog.51cto.com/babyhe/1118372
