PHP แสดง Data Dictionary สำหรับ Mysql

พอดีต้องการทำ 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
You can leave a response, or trackback from your own site. Responses are currently closed, but you can trackback from your own site. You can skip to the end and leave a response. Pinging is currently not allowed. Both comments and pings are currently closed.
Powered by WordPress | Shop Free T-Mobile Phones Online | Thanks to Verizon Phones without Contract, MMORPG Games and Sell Car