1 <? PHP 2/** 3 * generate Mysql Data Dictionary 4*5 * @ version $ ID $6 * @ author niming <287384795@qq.com> 7 */8 9 // configure Database 10 $ dbserver = "localhost "; 11 $ dbusername = "root"; 12 $ dbpassword = "root"; 13 $ database = 'mydb'; 14 // other configuration 15 $ Title = 'System data dictionary '; 16 17 $ mysql_conn = @ mysql_connect ("$ dbserver", "$ dbusername", "$ dbpassword") or die ("MySQL connect is error. "); 18 mysql_select_db ($ database, $ mysql_conn); 19 mysql_query ('se T names utf8', $ mysql_conn); 20 $ table_result = mysql_query ('show tables ', $ mysql_conn ); 21 // retrieve all table names 22 while ($ ROW = mysql_fetch_array ($ table_result) {23 $ tables [] ['table _ name'] = $ row [0]; 24} 25 26 // cyclically obtain all table remarks 27 foreach ($ tables as $ k => $ v) {28 $ SQL = 'select * from'; 29 $ SQL. = 'information _ schema. tables '; 30 $ SQL. = 'where'; 31 $ SQL. = "table_name = '{$ V ['table _ name']}' and table_schema = '{$ dat Abase} '"; 32 $ table_result = mysql_query ($ SQL, $ mysql_conn); 33 while ($ T = mysql_fetch_array ($ table_result )) {34 $ tables [$ K] ['table _ comment'] = $ t ['table _ comment']; 35} 36 37 $ SQL = 'select * from '; 38 $ SQL. = 'information _ schema. columns '; 39 $ SQL. = 'where'; 40 $ SQL. = "table_name = '{$ V ['table _ name']}' and table_schema = '{$ database}'"; 41 42 $ fields = array (); 43 $ field_result = mysql_query ($ SQL, $ Mysql_conn); 44 While ($ T = mysql_fetch_array ($ field_result) {45 $ fields [] = $ t; 46} 47 $ tables [$ K] ['column'] = $ fields; 48} 49 mysql_close ($ mysql_conn); 50 51 52 $ html = ''; 53 // loop all tables 54 foreach ($ tables as $ K =>$ v) {55 $ HTML. = '<p> <H2> '. $ V ['table _ comment']. '& nbsp; </H2>'; 56 $ HTML. = '<Table border = "1" cellspacing = "0" cellpadding = "0" align = "center">'; 57 $ HTML. = '<caption> '. $ V ['table _ name'].' </Caption> '; 58 $ HTML. = '<tbody> <tr> <TH> Field name </Th> <TH> data type </Th> <TH> default value </Th> 59 <TH> allow non-null </Th> 60 <TH> auto-increment </Th> <TH> remarks </Th> </tr> '; 61 $ HTML. = ''; 62 63 foreach ($ V ['column '] as $ f) {64 $ HTML. = '<tr> <TD class = "C1"> '. $ f ['column _ name']. '</TD>'; 65 $ HTML. = '<TD class = "C2"> '. $ f ['column _ type']. '</TD>'; 66 $ HTML. = '<TD class = "C3"> & nbsp ;'. $ f ['column _ default']. '</TD>'; 67 $ HTML. = '<TD class = "C4"> & nbsp ;'. $ F ['is _ nulllable']. '</TD>'; 68 $ HTML. = '<TD class = "C5"> '. ($ f ['extra '] = 'Auto _ secret '? 'Yes': '& nbsp ;'). '</TD>'; 69 $ HTML. = '<TD class = "C6"> & nbsp ;'. $ f ['column _ comment']. '</TD>'; 70 $ HTML. = '</tr>'; 71} 72 $ HTML. = '</tbody> </table> </P>'; 73} 74 75 76 // output 77 echo '<HTML> 78