Home>Article>Backend Development> PHP implementation example of generating data dictionary function
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 .= '
字段名 | 数据类型 | 默认值 | 允许非空 | 自动递增 | 备注 |
---|---|---|---|---|---|
' . $f['COLUMN_NAME'] . ' | '; $html .= '' . $f['COLUMN_TYPE'] . ' | '; $html .= '' . $f['COLUMN_DEFAULT'] . ' | '; $html .= '' . $f['IS_NULLABLE'] . ' | '; $html .= '' . ($f['EXTRA']=='auto_increment'?'是':' ') . ' | '; $html .= '' . $f['COLUMN_COMMENT'] . ' | '; $html .= '
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!