<?php
#------------------------------------------------------------------------------------------------------------------------------------------
#    Programmer  : Sirichai Teerapattarasakul
#    NickName : TaTump
#    Email : tump_si@yahoo.com
#    Msn : tump_si@hotmail.com
#    Website : http://www.memo8.com
#------------------------------------------------------------------------------------------------------------------------------------------

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        
?>