First create a database "test" in mysql, and then create a database table "ly" in the database.
Create a test database first:
<?php // 创建连接 $conn = new mysqli("localhost", "uesename", "password"); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error);} // 创建数据库 $sql = "CREATE DATABASE test"; if ($conn->query($sql) === TRUE) { echo "数据库创建成功"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>
Set the following fields:
id: It is unique, type is int, and select the primary key.
nackname: User nickname, type is varchar, length is 30.
message: message content, type is text. Although the text type field also belongs to a character type, its size cannot be specified.
lytime: The message content release time, the type is datetime, no need to set the length.
reply: The content of the reply message, type is text.
retime: The time to reply to the message, the type is datetime, no need to set the length.
SQL statement to create a database table:
<?php $SQL = " CREATE TABLE IF NOT EXISTS `ly` ( `id` int(10) NOT NULL AUTO_INCREMENT, `nickname` varchar(30) CHARACTER SET utf8 NOT NULL, `message` text CHARACTER SET utf8 NOT NULL, `avatar` varchar(50) CHARACTER SET utf8 NOT NULL, `lytime` datetime NOT NULL, `reply` text CHARACTER SET utf8 NOT NULL, `retime` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 "; ?>
In this way, we have completed the creation of the database table.
Next Section