Create database and tables for background administrator login

Since it is the background, we need to set up the administrator login function. For the use of website administrators, we have made rigid regulations on the administrator account here, which is called "admin".

Next we will start to build a database for the entire video website, named vidoe. The creation code is as follows:

<?php
// 创建连接
$conn = new mysqli("localhost", "uesename", "password");
// 检测连接
if ($conn->connect_error) 
{    
    die("连接失败: " . $conn->connect_error);} 
    // 创建数据库
    $sql = "CREATE DATABASE vidoe";
        if ($conn->query($sql) === TRUE) 
        {    
        echo "数据库创建成功";
        } else {    
        echo "Error creating database: " . $conn->error;
        }
    $conn->close();
?>

Create an administrator table in the database named admin.

Set the following fields:

id: It is unique, type is int, and select the primary key.

username: Administrator name, type is varchar, length is 50.

password: Password, type is varchar, length is 50.

<?php
$SQL = " CREATE TABLE IF NOT EXISTS `admin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  `password` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ";
?>

Add an administrator username and password:

<?php
$SQL = "INSERT INTO admin (id , username, password) VALUES ('1', 'admin', '12345');"
?>

Display the following results in the database:

3.png

Continuing Learning
||
<?php // 创建连接 $conn = new mysqli("localhost", "uesename", "password"); // 检测连接 if ($conn->connect_error) { die("连接失败: " . $conn->connect_error);} // 创建数据库 $sql = "CREATE DATABASE vidoe"; if ($conn->query($sql) === TRUE) { echo "数据库创建成功"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>
submitReset Code