亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Database construction for PHP development login page

Database construction for login page


login.jpg

As we have said in the previous chapter, users The name and password must be stored in the data, so these two fields are essential. We name the username field "username" and the password "password".


Database creation

We can create a database through the mysql knowledge we have learned. This chapter uses our PHP Code to create our database

<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password);
 mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 
// 檢測連接
if (!$conn) {
    die("連接失敗: " . mysqli_connect_error());
}
// 創(chuàng)建數(shù)據(jù)庫
$sql = "CREATE DATABASE login";
if (mysqli_query($conn, $sql)) {
    echo "數(shù)據(jù)庫創(chuàng)建成功";
} else {
    echo "數(shù)據(jù)庫創(chuàng)建失敗: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

The above code creates a database named login


Create data table

The data table is named: user

Field nameidusernamepassword
Field typeINT
VARCHAR
VARCHAR
Field length63030
Field descriptionUser’s idUsername password

The data table and field creation code is as follows


<?php
header("Content-type:text/html;charset=utf-8");    //設(shè)置編碼
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "login";
// 創(chuàng)建連接
$conn = mysqli_connect($servername, $username, $password, $dbname);
 mysqli_set_charset($conn,'utf8'); //設(shè)定字符集 
// 檢測連接
if (!$conn) {
    die("連接失敗: " . mysqli_connect_error());
}
// 使用 sql 創(chuàng)建數(shù)據(jù)表
$sql = "CREATE TABLE user (
 id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
 username VARCHAR(30) NOT NULL,
 password VARCHAR(30) NOT NULL
 );";
if (mysqli_query($conn, $sql)) {
    echo "數(shù)據(jù)表 user 創(chuàng)建成功";
} else {
    echo "創(chuàng)建數(shù)據(jù)表錯(cuò)誤: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

The above code creates a database named "user", which contains "id", "username" and "password" Field

Let’s open phpmyadmin and take a look

12.jpg


. We can see that our database has been set up. Of course, this is just the simplest and basic one. After setting up our database, we can create our HTML display page



Continuing Learning
||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>頁面登錄</title> </head> <body> <h2>數(shù)據(jù)庫搭建</h2> </body> </html>
submitReset Code