Database Analysis
The main functions implemented by this project are user registration and login, publishing posts, and replying to posts. Based on this judgment, user tables and posts need to be designed. The two tables of content table
The user table user contains the following fields:
Field name | Field type | Field length | Field description |
id | int | 30 | Number, primary key, auto-increment |
username | varchar | 30 | Username |
password | varchar | 40 | Password |
The post table tiezi contains the following fields:
Field name | Field type | Field length | Field Description |
id | int | 30 | Number, primary key, auto-increment |
userId | int | 30 | User id of the user table |
fId | int | 30 | Indicates the affiliation of the post |
title | varchar | 50 | Post Title |
content | text |
| ## Content of the post |
timestamp | varchar | 30 | Post time |
num | int | 20 | Post views |
Database creation
We run mysql in the command prompt window (specifically how to use the command prompt To connect to the database in the character window, you can refer to Section 2.2 in our previous course "PHP Development Login Registration Tutorial")
After successfully connecting to the database, copy the complete statement to create the database below into the window , press the Enter key to prompt that the creation is successful, as shown below
![1480578530162164.png 创建数据库截图.png](http://img.php.cn/upload/image/897/323/483/1480578530162164.png)
Creation The complete statement of the database is as follows
DROP DATABASE IF EXISTS tieba;
CREATE DATABASE tieba DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE tieba;
CREATE TABLE IF NOT EXISTS `user` (
`id` int(30) NOT NULL AUTO_INCREMENT,
`username` varchar(30) NOT NULL,
`password` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
INSERT INTO `user` (`username`, `password`) VALUES
('admin', '21232f297a57a5a743894a0e4a801fc3');
CREATE TABLE IF NOT EXISTS `tiezi` (
`id` int(30) NOT NULL AUTO_INCREMENT,
`userId` int(30) NOT NULL,
`fId` int(30) NOT NULL,
`title` varchar(50) NOT NULL,
`content` text NOT NULL,
`timestamp` varchar(30) NOT NULL,
`num` int(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=39 ;
Next SectionDROP DATABASE IF EXISTS tieba;
CREATE DATABASE tieba DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE tieba;
CREATE TABLE IF NOT EXISTS `user` (
`id` int(30) NOT NULL AUTO_INCREMENT,
`username` varchar(30) NOT NULL,
`password` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
INSERT INTO `user` (`username`, `password`) VALUES
('admin', '21232f297a57a5a743894a0e4a801fc3');
CREATE TABLE IF NOT EXISTS `tiezi` (
`id` int(30) NOT NULL AUTO_INCREMENT,
`userId` int(30) NOT NULL,
`fId` int(30) NOT NULL,
`title` varchar(50) NOT NULL,
`content` text NOT NULL,
`timestamp` varchar(30) NOT NULL,
`num` int(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=39 ;