Home  >  Article  >  Backend Development  >  PHP realizes the function of generating data dictionary

PHP realizes the function of generating data dictionary

不言
不言Original
2018-06-01 10:28:321447browse

This article mainly introduces the function of generating data dictionary in PHP, involving PHP's common connection, data table query, traversal, table table composition and other related operation skills for mysql. Friends who need it can refer to it

The example in this article describes how PHP implements the function of generating a data dictionary. I would like to share it with you for your reference. The details are as follows:

I am pressed for time recently and have no time to post a blog. I would like to share a knowledge point with you while I have some time now. When we are doing development, we may often encounter the problem of analyzing the database and making a data dictionary. Now the benefit is here. You only need to follow the link I sent to easily help you design the data dictionary. You don’t need to download the data dictionary tool. As a developer, you should be able to get this knowledge with just a few lines of code. So I won’t go into nonsense now. Look at the code below. You only need to change your database account and Just enter the password and run it.

Effect display:

After talking so much nonsense, I finally started writing code:


$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 = '';
//循环所有表
foreach ($tables AS $k=>$v) {
   //$html .= '

'. $v['TABLE_COMMENT'] . '

'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($v['COLUMN'] AS $f) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . $v['TABLE_NAME'] .' '. $v['TABLE_COMMENT']. '
字段名数据类型默认值 允许非空 自动递增备注
' . $f['COLUMN_NAME'] . '' . $f['COLUMN_TYPE'] . ' ' . $f['COLUMN_DEFAULT'] . ' ' . $f['IS_NULLABLE'] . '' . ($f['EXTRA']=='auto_increment'?'是':' ') . ' ' . $f['COLUMN_COMMENT'] . '

'; } //输出 echo ' '.$title.'
'; echo '

'.$title.'

'; echo $html; echo ''; ?>

The above is the entire content of this article, thank you for reading. Please pay attention to the PHP Chinese website for more information!

Related recommendations:

PHP implements the function of uploading files through CURL

PHP implements the function of uploading images to the database and displaying the output method

The above is the detailed content of PHP realizes the function of generating data dictionary. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn