PHP generates MySQL data dictionary data table structure

Source: Internet
Author: User
Tags mysql connect

<?php/** * Generate MySQL data dictionary *///config Database $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 notes for all tables and column messages in the table foreach ($tab    Les 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 _result = 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 border= "1" cellspacing= "0" cellpadding= "0" align= "Center" &    gt; '; $html. = ' <caption> table name: '. $v [' table_name ']. ‘ ‘ . $v [' table_comment '].    ' </caption> '; $html. = ' <tbody><tr><th> field name </th><th> data type </th><th> default value </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. = ' &LT;TD class= ' c5 ' > '. ($f [' EXTRA '] = = ' auto_increment '? Is ': ').        ' </td> '; $html. = ' <td class= ' C6 ' > '. $f [' column_comment '].        ' </td> ';    $html. = ' </tr> '; } $html. = ' </tbody></table></p> ';} /* Generate Word *///header ("Content-type:application/vnd.ms-word");//header ("content-disposition:attachment;filename={ $database [' db_name '} data dictionary. doc ");//Output echo ' 

This article turns from http://www.oicto.com/category/php/

PHP generates MySQL data dictionary data table structure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.