首页
开发手册
应用中心
工具
用户中心
FoundPHP Database Design
English
中文简体
English
上一篇
下一篇
### FoundPHP Database Design FoundPHP database currently supports 6 types, the most commonly used is Mysql. For versatility and compatibility with multiple databases, we give some suggestions and standards, so that the code you develop has better compatibility and higher performance operation. #### 1. Standard As the database is updated, more requirements will become more and more stringent. FoundPHP has designed a new structure that allows the database to adapt to various platform databases while ensuring stable execution efficiency and expansion. The overall use of arrays . #### 2. Structure Most developers design databases with a multi-table structure, such as several types of users: principals, teachers, students, and administrators. Most of the time, they will design a table for each user type. This is easier to store, but 85% The structure is almost the same, but the database efficiency is lower, but such a design structure and cost will be very low. When designing a database, we need to consider invocation and reuse, so we usually standardize the concept similar to mvc. For example, when we design the user table `user`, the primary key is named uid. If the table is `article`, the primary key is named aid. If the user table is not enough to put the teacher's information, you can expand a sub table, and the primary key of `user_teacher` is named utid, so that we have a pattern. ``` -- -- user table `foundphp_user` -- CREATE TABLE `foundphp_user` ( `uid` int(11) UNSIGNED NOT NULL, `fid` int(11) DEFAULT '0' COMMENT 'Parent id', `types` int(2) NOT NULL COMMENT 'User type: 1 ordinary registration 2 WeChat authorized access', `username` varchar(40) NOT NULL COMMENT 'username', `password` varchar(32) NOT NULL COMMENT 'password', `forget_password` varchar(10) DEFAULT NULL COMMENT 'retrieve password', `forget_date` int(10) DEFAULT NULL COMMENT 'retrieve password time', `gender` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'gender: 1 male, 2 female', `birth_y` int(11) DEFAULT '0' COMMENT 'birthday', `birth_m` int(11) DEFAULT '0' COMMENT 'birthday month', `birth_d` int(11) DEFAULT '0' COMMENT 'birthday date', `age` varchar(20) DEFAULT '0' COMMENT 'age', `email` varchar(80) DEFAULT NULL COMMENT 'mailbox', `phone` varchar(120) DEFAULT NULL COMMENT 'phone', `province` varchar(50) DEFAULT NULL COMMENT 'province', `city` varchar(50) DEFAULT NULL COMMENT 'city', `district` varchar(50) DEFAULT NULL COMMENT 'district', `address` varchar(50) DEFAULT NULL COMMENT 'address', `openid` varchar(60) DEFAULT NULL COMMENT 'wechat openid', `states` int(11) NOT NULL DEFAULT '0' COMMENT 'Status: 1 activated, 0 unable to log in', `state_date` int(11) DEFAULT '0' COMMENT 'account expiration time', `reg_date` int(11) NOT NULL DEFAULT '0' COMMENT 'registration time', `reg_ip` varchar(15) NOT NULL COMMENT 'register IP', `last_date` int(10) DEFAULT '0' COMMENT 'last login time', `last_ip` varchar(15) DEFAULT NULL COMMENT 'last loginip' ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='total list of users' ROW_FORMAT=DYNAMIC; -- -- table index `foundphp_user` -- ALTER TABLE `foundphp_user` ADD PRIMARY KEY (`uid`) USING BTREE, ADD KEY `fid` (`fid`) USING BTREE, ADD KEY `types` (`types`) USING BTREE, ADD KEY `states` (`states`) USING BTREE; -- -- use tableAUTO_INCREMENT `foundphp_user` -- ALTER TABLE `foundphp_user` MODIFY `uid` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1000; COMMIT; ```` #### 3. Application After the increase in the number of visits in a development project, the efficiency is often affected by the database. It is usually cached to reduce the application of the database. However, most websites use database queries. As the functions increase, the increase in the number of sentences will also cause the project speed to decrease or even Card machine, here we will talk about the amount of database application, FoundPHP provides a database debugging platform, you can reduce database statements through the debugging platform, which will be explained later. #### 4.Backup and Restore A large amount of data will be generated after the project is applied for a long time, and database backup is also the top priority. Therefore, the table structure of the database also needs to be done well for the recovery of the database, and the database can be as complete as possible during the recovery. -You can use Database Master for big data backup and recovery -It is also a good choice to use the pagoda automatic backup solution.