Database Dictionary generation
Php generates mysql database data dictionary
- /**
- * Generate a mysql data dictionary
- */
- Header ("Content-type: text/html; charset = utf-8 ");
- // Configure the database
- $ Dbserver = "127.0.0.1 ";
- $ Dbusername = "root ";
- $ Dbpassword = "";
- $ Database = "think_team ";
- // Other configurations
- $ 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 );
- $ No_show_table = array (); // A table that does not need to be displayed
- $ No_show_field = array (); // fields that do not need to be displayed
- // Obtain all table names
- While ($ row = mysql_fetch_array ($ table_result )){
- If (! In_array ($ row [0], $ no_show_table )){
- $ Tables [] ['Table _ name'] = $ row [0];
- }
- }
- // Replace the table prefix
- If ($ _ GET ['prefix']) {
- $ Prefix = 'czzj ';
- Foreach ($ tables as $ key => $ val ){
- $ TableName = $ val ['Table _ name'];
- $ String = explode ('_', $ tableName );
- If ($ string [0]! = $ Prefix ){
- $ String [0] = $ prefix;
- $ NewTableName = implode ('_', $ string );
- Mysql_query ('Rename Table'. $ tableName. 'to'. $ newTableName );
- }
- }
- Echo "replaced successfully! "; Exit ();
- }
- // Cyclically obtain the remarks and column messages of all tables
- Foreach ($ tables as $ k => $ 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 = '';
- // Loop all tables
- Foreach ($ tables as $ k => $ v ){
- $ Html. = ''. ($ k + 1 ). ','. $ v ['Table _ comment']. '('. $ v ['Table _ name']. ')'. "\ n ";
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- $ Html. ='
- }
- $ Html. ='
- Foreach ($ v ['column'] as $ f ){
- If (! Is_array ($ no_show_field [$ v ['Table _ name']) {
- $ No_show_field [$ v ['Table _ name'] = array ();
- }
- If (! In_array ($ f ['column _ name'], $ no_show_field [$ v ['Table _ name']) {
- $ Html. ='
- }
- $ Html. ='
'. "\ N ";
'. "\ N ";
'. "\ N ";
Field name | '. "\ N ";
Data type | '. "\ N ";
Default value | '. "\ N ";
Allow non-empty | '. "\ N ";
Auto increment | '. "\ N ";
Remarks | '. "\ N ";
'. "\ N ";
'. "\ N ";
'. $ F ['column _ name'].' | '. "\ N ";
'. $ F ['column _ type'].' | '. "\ N ";
'. $ F ['column _ default'].' | '. "\ N ";
'. $ F ['is _ nulllable'].' | '. "\ N ";
'. ($ F ['Extra'] = 'auto _ secret '? 'Yes ':'').' | '. "\ N ";
'. $ F ['column _ comment'].' | '. "\ N ";
'. "\ N ";
'. "\ N ";
'. "\ N ";
- }
- ?>
-
- Code generated by tengsu Technology Co., Ltd. database data dictionary
-
-
-
- Code generated by tengsu Technology Co., Ltd. database data dictionary
-
|