พอดีต้องการทำ Data Dictionary แต่ server ไม่มี phpMyAdmin ก็เลยเขียน php แบบง่ายๆขึ้นมาเพื่อแสดง Data Dictionary เลยเอามาโพสไว้ในเว็บเผื่อใครต้องการครับ Download ที่นี่
Source code
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename="data_dictionary.xls"');#ชื่อไฟล์
/*----------------------
Config Database
-----------------------*/
$strCfgDbHost = "localhost";
$strCfgDbUser = "root";
$strCfgDbPass = "";
$strCfgDbName = "";
$objDb = mysql_connect($strCfgDbHost,$strCfgDbUser,$strCfgDbPass);
mysql_select_db($strCfgDbName);
if (!$objDb) { die('Could not connect: ' . mysql_error()); }
mysql_query("SET NAMES UTF8");
mysql_query("SET character_set_results=utf8");
$sql = "SHOW TABLES";
$rs = mysql_query($sql);
$i=0;
while($row = @mysql_fetch_array($rs)){
$tableArr[$i] = $row[0];
$i++;
}
@mysql_free_result($rs);
$html="";
foreach ($tableArr as $table) {
$sql="DESCRIBE $table;";
$rs = mysql_query($sql);
$html ="<h1>$table</h1>";
$html .="<br><br>";
$html .= "<TABLE border=\"1\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">
<TR>
<TD><b>Field</b></TD>
<TD><b>Type</b></TD>
<TD><b>Null</b></TD>
<TD><b>Key</b></TD>
<TD><b>Default</b></TD>
<TD><b>Extra</b></TD>
</TR>
";
while($row = @mysql_fetch_array($rs)){
$html .= "
<TR>
<TD>$row[0]</TD>
<TD>$row[1]</TD>
<TD>$row[2]</TD>
<TD>$row[3]</TD>
<TD>$row[4]</TD>
<TD>$row[5]</TD>
</TR>
";
}
@mysql_free_result($rs);
$html .="</TABLE>";
echo $html;
}// Loop
RSS Feed
Twitter
August 2nd, 2010
admin | 1,643 views
Posted in
Tags: 
