Php generates a mysql database data dictionary. Php generates the mysql database data dictionary program code. the specific code is as follows :? Phpheader (Content-type: texthtml; charsetutf-8); ** php generates mysql database data dictionary
Php generates the mysql database data dictionary program code, which is more practical. the specific code is as follows:
* // Configure the database $ dbserver = "localhost"; $ dbusername = "root"; $ dbpassword = "root"; $ database = 'test '; // Other configurations $ title = $ database. 'database data dictionary '; $ 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 ); // Obtain all TABLE names while ($ row = mysql_fetch_array ($ table_result) {$ tables [] ['Table _ name'] = $ row [0];} // cyclically obtain the remarks 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. ='
'; $ Html. ='
'. $ V ['Table _ comment'].' ('. $ v ['Table _ name'].')
'; $ Html. ='
Field name |
Data type |
Default value |
Allow non-empty |
Remarks |
'; $ Html. = ''; foreach ($ v ['column'] AS $ f) {$ html. ='
'. $ F ['column _ name'].' | '; $ Html. ='
'. $ F ['column _ type'].' | '; $ Html. ='
'. $ F ['column _ default'].' | '; $ Html. ='
'. $ F ['is _ nulllable'].' | '; $ Html. ='
'. $ F ['column _ comment']. ($ f ['Extra'] = 'auto _ secret '? ', Auto increment ':'').' | '; $ Html. ='
';} $ Html. ='
';} // Output echo''. $ Title .''; Echo ''. $ title.''; echo $ html; $ version ='
Made by www.phpernote.com
'; Echo'
'. $ Version .'
';
The generate result page is shown in the following figure:
Articles you may be interested in
- Rational Use of MySQL database indexes to make the database run efficiently
- Php uses the session_set_save_handler () function to save the session to the MySQL database.
- How to forget the MySQL database password of PHPnow
- Summarize the causes and solutions for the slow MySQL database server
- Php uses array_flip to implement array key-value exchange to remove array duplicate values
- Php mysql database operations
- In php, we use the curl post method to submit data and the get method to obtain webpage data.
- How to modify the character set of a mysql database
Php generates the mysql database data dictionary program code, which is more practical. the specific code is as follows :? Phpheader ('content-type: text/html; charset = utf-8 ');/**...