查看數據庫表結構的PHP代碼
<?php /* discuz 顯示論壇表,結構by lost63.com 2010.8.17 / $dbhost='localhost'; //服務器 $dbuser='root'; //用戶名 $dbpw='myoa888'; //密碼 $dbname='pipiqiu'; //數據庫名 $tablepre='pre_'; //表前綴 header("Content-type:text/html; char=gb2312"); mysql_connect($dbhost,$dbuser,$dbpw) or die('數據庫連接失敗'); mysql_query("set names gb2312"); mysql_select_db($dbname) or die('找不到數據庫'); echo '<style>{font-size:12px;}.fenlei{width:250px;float:left;display:inline;}.pic{height:60px;float:left;display:inline;}</style>';
$tb_names=mysql_list_tables($dbname);
$tables=array(); //表名數組
/ 數據庫所有表 / while($row=mysql_fetch_row($tb_names)){ $tables[]=$row[0]; } echo $dbname.'該數據庫含有<font color=red>'.count($tables).'</font>個表,顯示如下:<br>'; echo '<div class="fenlei"></div>'; foreach($tables as $v){ echo '<div class="fenlei">'.$v.'</div>'; } echo '</table>';
/ 結構顯示 / echo '<p>======================= 結構顯示 ======================= </p>'; for($i=0;$i<count($tables);$i++){ $query=mysql_query("select * from
".$tables[$i]."
");while($row=mysql_fetch_field($query)){ $fd.=str_pad(" ",2).$row->name." ".$row->type."(".$row->max_length."),"; } $fd=substr($fd,0,-1)."n"; $fd=str_replace(",",",n",$fd);
echo '<table width="100" border="0" cellpadding="8" cellspacing="1" bgcolor="#CCCCCC" style="float:left;display:inline;margin-left:4px;margin-top:4px;"> <tr> <td align="center" bgcolor="#FFFFFF"><strong>'.$tables[$i].'</strong></td> </tr> <tr> <td bgcolor="#FFFFFF">'.$fd.'</td> </tr> </table>'; unset($fd); }
echo '<p style="clear:both;">======================= 顯示完畢 ======================= </p>'; ?> </pre>