Php generates mysql database data dictionary _ PHP Tutorial

Source: Internet
Author: User
Tags mysql connect
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. ='
  
  '; $ Html. ='
  
  '; $ Html. = ''; foreach ($ v ['column'] AS $ f) {$ html. =' 
   '; $ Html. =' 
    '; $ Html. =' 
    '; $ Html. =' 
    '; $ Html. =' 
    '; $ Html. =' 
   ';} $ Html. =' 
  
'. $ V ['Table _ comment'].' ('. $ v ['Table _ name'].')
Field name Data type Default value Allow non-empty Remarks
'. $ F ['column _ name'].''. $ F ['column _ type'].''. $ F ['column _ default'].''. $ F ['is _ nulllable'].''. $ F ['column _ comment']. ($ f ['Extra'] = 'auto _ secret '? ', Auto increment ':'').'

';} // 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 ');/**...

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.