Home>Article>Backend Development> PHP implementation example of generating data dictionary function

PHP implementation example of generating data dictionary function

jacklove
jacklove Original
2018-06-22 15:48:18 1391browse

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 ''; ?>

Articles you may be interested in:

Related explanations of basic operations of the CodeIgniter framework database

PHP method to get all dates this week or all dates in the last seven days

php lcg_value and mt_rand generate 0~1 random decimal effect comparison

The above is the detailed content of PHP implementation example of generating data dictionary function. 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