<?php/** * Generate MySQL data dictionary word *///metabase $database = Array (); $database [' db_host '] = ' 127.0.0.1 '; $database [' db_name '] = ' Cqhshop '; $database [' db_user '] = ' root '; $database [' db_pwd '] = ' 123456 '; $mysql _conn = @mysql_connect ("{$database [' db_ HOST ']} "," {$database [' Db_user ']} "," {$database [' db_pwd ']} ") or Die (" Mysql Connect is error. "); mysql_select_db ($database [' db_name '], $mysql _conn), $result = mysql_query (' Show Tables ', $mysql _conn); mysql_query (' SET NAME GBK ', $mysql _conn); Get all table names while ($row = Mysql_fetch_array ($result)) {$tables [] [' table_name '] = $row [0];}//Loop to get all table notes and table column messages foreach ($ Tables as $k + $v) {$sql = ' SELECT * from '; $sql. = ' Information_schema. TABLES '; $sql. = ' WHERE '; $sql. = ' table_name = ' {$v [' table_name '} ' and Table_schema = ' {$database [' db_name ']} '; $table _r Esult = mysql_query ($sql, $mysql _conn), while ($t = mysql_fetch_array ($table _result)) {$tables [$k] [' table_comment '] = $t [' Table_comment '];} $sql = ' SELECT * from '; $sql. = ' Information_schema. COLUMNS '; $sql. = ' WHERE ';$sql. = "table_name = ' {$v [' table_name '} ' and Table_schema = ' {$database [' db_name ']} '"; $fields = Array (); $field _result = mysql_query ($sql, $mysql _conn), while ($t = mysql_fetch_array ($field _result)) {$fields [] = $t;} $tables [$k] [' COLUMN '] = $fields;} Mysql_close ($mysql _conn); $html = "; Loop all tables foreach ($tables as $k = = $v) {$html. = ' <table style= "text-align:center;" border= "1" cellspacing= "0" Cellpad ding= "0" align= "center" > "$html. = ' <caption> table name: '. $v [' table_name ']. ‘ ‘ . $v [' table_comment ']. ' </caption> '; $html. = ' <tbody><tr><th> field name </th><th> data type </th><th> Default </th><th> allow non-null </th><th> auto increment </th><th> remarks </th></tr> '; $html. = '; foreach ($v [' COLUMN '] as $f) {$html. = ' <td class= ' C1 ' > '. $f [' column_name ']. ' </td> '; $html. = ' <td class= "C2" > ". $f [' Column_type ']. ' </td> '; $html. = ' <td class= "C3" > ". $f [' Column_default ']. ' </td> '; $html. = ' <td class= "c4 ">". $f [' is_nullable ']. ' </td> '; $html. = ' <TD class= "C5" > ". ($f [' EXTRA '] = = ' auto_increment '? Is ': '). ' </td> '; $html. = ' <td class= "C6" > ". $f [' column_comment ']. ' </td> '; $html. = ' </tr> ';} $html. = ' </tbody></table> '; $html. = ' <br/><br/> ';} Output header ("Content-type:application/vnd.ms-word"); Header ("Content-disposition:attachment;filename={$database [ ' Db_name ']} data dictionary. doc "); Echo $html;? >
PHP generates MySQL data dictionary word