This time I will bring you a detailed explanation of the steps to generate a data dictionary in PHP. What are the precautions for generating a data dictionary in PHP? Here is a practical case, let's take a look.
I’m pressed for time recently, and I don’t have time to post a blog. I’d like to take advantage of the time now to share a knowledge point with you. 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 .= '
I believe you will read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to implement ADODB transaction processing in PHP
How to use Thinkphp5 uploadify to implement file upload
The above is the detailed content of Detailed explanation of the steps to generate data dictionary in PHP. For more information, please follow other related articles on the PHP Chinese website!