国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP development student management system database creation

Let’s first take a look at the fields to be stored in our database

stu.jpg

We will store the information in the above picture into the database

  • Name

  • ageage

  • gender sex

  • Class class


Now that we know the fields to be stored, let’s create our database first


Create database

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


Create data table

A 'stu' table was created in the "study" database

##Field name idnameagesexclass Field typeINTVARCHARINTVARCHARVARCHAR Field length65062050Field descriptionStudent idStudent nameStudent ageStudent’s genderStudent’s Class





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


We have already created the database, below The first step is to create our HTML page



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