MySQL Data dictionary code

Source: Internet
Author: User

Usually do development, look at the MySQL table is used navicat, although it is convenient to view the individual table fields, but to see the entire database of the individual fields of the details of the table is not so convenient, so I found a piece of code on the Internet, the database all the table fields are displayed, This will make the view structure clearer.

Show effect

1<?PHP2 /**3 * Generate MySQL data dictionary4  */5 Header("content-type:text/html; Charset=utf-8 " );6  7 //Configuration Database8 $dbserver= "localhost";//Database IP Address9 $dbusername= "Root";//Database user nameTen $dbpassword= "";//Database Password One $database= "Test";//Database name A   - //Other configurations - $title= ' Data dictionary '; the   - $mysql _conn= @mysql_connect( "$dbserver", "$dbusername", "$dbpassword") or die("Mysql Connect is error.") ); - mysql_select_db($database,$mysql _conn ); - mysql_query(' SET NAMES UTF8 ',$mysql _conn ); + $table _result=mysql_query(' Show Tables ',$mysql _conn ); - //get all the table names +  while($row=Mysql_fetch_array($table _result ) ) { A     $tables[] [' table_name '] =$row[0]; at } -   - //Loop to get notes for all tables and column messages in the table - foreach($tables  as $k=$v ) { -     $sql= ' SELECT * from '; -     $sql. = ' Information_schema. TABLES '; in     $sql. = ' WHERE '; -     $sql. = "table_name = ' {$v[' table_name ']} ' and Table_schema = ' {$database}‘"; to     $table _result=mysql_query($sql,$mysql _conn ); +      while($t=Mysql_fetch_array($table _result ) ) { -         $tables[$k] [' table_comment '] =$t[' Table_comment ']; the     } *       $     $sql= ' SELECT * from ';Panax Notoginseng     $sql. = ' Information_schema. COLUMNS '; -     $sql. = ' WHERE '; the     $sql. = "table_name = ' {$v[' table_name ']} ' and Table_schema = ' {$database}‘"; +       A     $fields=Array (); the     $field _result=mysql_query($sql,$mysql _conn ); +      while($t=Mysql_fetch_array($field _result ) ) { -         $fields[] =$t; $     } $     $tables[$k] [' COLUMN '] =$fields; - } - Mysql_close($mysql _conn ); the   - $html= ' ';Wuyi //Loop All Tables the foreach($tables  as $k=$v ) { -     //$html. = ' <p> Wu     $html. = ' <table border= ' 1 "cellspacing=" 0 "cellpadding=" 0 "align=" center "> '; -     $html. = ' <caption> '.$v[' table_name ']. ‘ ‘ .$v[' Table_comment ']. ' </caption> '; About     $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. = '; -       A     foreach($v[' COLUMN '] as $f ) { +         $html. = ' <tr><td class= ' C1 ' > '.$f[' column_name ']. ' </td> '; the         $html. = ' <td class= ' C2 ' > '.$f[' Column_type ']. ' </td> '; -         $html. = ' <td class= ' C3 ' >&nbsp; '.$f[' Column_default ']. ' </td> '; $         $html. = ' <td class= ' C4 ' >&nbsp; '.$f[' is_nullable ']. ' </td> '; the         $html. = ' &LT;TD class= ' c5 ' > '. ($f[' EXTRA '] = = ' auto_increment '? ' Yes ': ' &nbsp; ') . ' </td> '; the         $html. = ' <td class= ' c6 ' >&nbsp; '.$f[' Column_comment ']. ' </td> '; the         $html. = ' </tr> '; the     } -     $html. = ' </tbody></table></p> '; in } the   the //Output About Echo‘ the  the <meta http-equiv= "Content-type" content= "text/html; charset=utf-8" /> the<title> '.$title. ‘</title> + <style> - body,td,th {font-family: "Song body"; font-size:12px;} the table{border-collapse:collapse;border:1px solid #CCC; background: #6089D4;}Bayi table caption{text-align:left; Background-color: #fff; line-height:2em; font-size:14px; font-weight:bold;} the table th{text-align:left; font-weight:bold;height:26px; line-height:25px; font-size:16px; border:3px solid #fff; Color: #ffffff; padding:5px;} the table td{height:25px; font-size:12px; border:3px solid #fff; Background-color: #f0f0f0; padding:5px;} - . c1{width:150px;} - . c2{width:130px;} the . c3{width:70px;} the . c4{width:80px;} the . c5{width:80px;} the . c6{width:300px;} - </style> the  the<body> '; the Echo' 

$title. ' ;94 Echo $html; the Echo' </body>; the the?>

MySQL Data dictionary code

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.