PHP development simple post bar database construction

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

idint30Number, primary key, auto-increment
usernamevarchar30Username
passwordvarchar40Password

The post table tiezi contains the following fields:

## Content of the posttimestampvarchar30Post timenumint20Post 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

创建数据库截图.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 ;
Continuing Learning
||
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 ;
submitReset Code
Field nameField typeField lengthField Description
idint30Number, primary key, auto-increment
userIdint30User id of the user table
fIdint30Indicates the affiliation of the post
titlevarchar50Post Title
contenttext