PHP generates MySQL data dictionary

Source: Internet
Author: User
Tags foreach sql mysql mysql connect

Sometimes we get a database of others, but there is no data dictionary, this PHP applet to help you easily solve.

The code is found on the Internet, of course, this code is just generated data dictionary, view, stored procedures and so on is the wood Oh.

 -->$v) {$sql = "select * from"; $sql. = "Information_schema."
    TABLES ";
    $sql. = "WHERE";
    $sql. = "table_name =" {$v ["table_name"]} "and Table_schema =" {$database} "";
    $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} "";
    $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 = ""; Loops All table foreach ($tables as $k => $v) {//$html. = "

". $v ["Table_comment"]. " "; $html. = "

"; $html. = " "; $html. = " "; $html. = ""; foreach ($v ["COLUMN"] as $f) {$html. = " "; $html. = " "; $html. = " "; $html. = " "; $html. = " "; $html. = " "; $html. = " "; } $html. = "
". $v ["table_name"]. " ". $v ["Table_comment"]. "
Field name Data Type Default Value allow non-null Auto Increment Notes
" . $f ["column_name"]. "" . $f ["Column_type"]. "" . $f ["Column_default"]. "" . $f ["Is_nullable"]. "" . ($f ["EXTRA"]== "auto_increment"?) is ":" ""." . $f ["Column_comment"]. "

"; } Output echo " <title>". $title."</title> "; echo "

". $title."

"; Echo $html; echo ""; ?>


Results after run:





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.