PHP development...LOGIN

PHP development news release system database construction

We have already said in the previous chapter that the news release we demonstrated only has "title", "news content" and "news release time". We only need to store these fields in the database

##Field descriptionNews idNews titleNews contentTime to publish news

Create database

We first create a database named "News", the code is as follows

<?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 News";
if (mysqli_query($conn, $sql)) {
    echo "数据库创建成功";
} else {
    echo "数据库创建失败: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

Create data table

Create a data table named new in the database named News, with the fields as in the above table

The code is as follows

<?php
header("Content-type:text/html;charset=utf-8");    //设置编码
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "News";
// 创建连接
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_set_charset($conn,'utf8'); //设定字符集
// 检测连接
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
// 使用 sql 创建数据表
$sql = "CREATE TABLE new (
 id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
 title VARCHAR(50) NOT NULL,
 content text NOT NULL,
 cre_time datetime
 );";
if (mysqli_query($conn, $sql)) {
    echo "数据表 user 创建成功";
} else {
    echo "创建数据表错误: " . mysqli_error($conn);
}
mysqli_close($conn);
?>

Now that our database and data table have been created, the next step is to write our HTML page



Next Section
<?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 News"; if (mysqli_query($conn, $sql)) { echo "数据库创建成功"; } else { echo "数据库创建失败: " . mysqli_error($conn); } mysqli_close($conn); ?>
submitReset Code
ChapterCourseware
    None
Field nameidtitle
content
cre_time
Field typeINT
VARCHAR
text
datetime
Field length650