Database construction of message board developed by PHP
Message board database construction
#In the previous chapter we completed our page layout. Click to leave a message and something like the picture below will appear. Form
From the picture above, we can see that the name, email address, and message content need to be inserted into the database, but when we look at the message, it usually has a date. , so we also need a date field in the database. Therefore, the fields in our database are as follows
Name name
Email email
Message content content
Message date ressage_time
Deposited We can build a database in the fields. This chapter uses PHP code to create a database. The code is as follows
Create a database
<?php header("Content-type:text/html;charset=utf-8"); //设置编码 $servername = "localhost"; $username = "root"; $password = "root"; // 创建连接 $conn = mysqli_connect($servername, $username, $password); mysqli_set_charset($conn,'utf8'); //设定字符集 // 检测连接 if (!$conn) { die("连接失败: " . mysqli_connect_error()); } // 创建数据库 $sql = "CREATE DATABASE message"; if (mysqli_query($conn, $sql)) { echo "数据库创建成功"; } else { echo "数据库创建失败: " . mysqli_error($conn); } mysqli_close($conn); ?>
The above code is created A database named message is created. After the database is built, we will create our data table
#Create data table
Table name Ressage_userid |
| name
| email
| contentressage_time | |
INT | |||||
6 | 30 | 50 | 200 | ||
User The id | The name of the message | The email address filled in the message | The content of the message | The message time |