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

Simple file upload to MySql database developed in PHP (1)

The previous section explained how to save files to a local directory through PHP code

In this section we explain how to upload files to the database.

First we need to create a test database:

<?php
// 創(chuàng)建連接
$conn = new mysqli("localhost", "uesename", "password");
// 檢測連接
if ($conn->connect_error) 
{    
    die("連接失敗: " . $conn->connect_error);} 
    // 創(chuàng)建數(shù)據(jù)庫
    $sql = "CREATE DATABASE test";
        if ($conn->query($sql) === TRUE) 
        {    
        echo "數(shù)據(jù)庫創(chuàng)建成功";
        } else {    
        echo "Error creating database: " . $conn->error;
        }
    $conn->close();
?>

Then we need to create a database img table, containing three content ids, title titles, and pic image addresses.

Set the following fields:

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

title: Title, type is varchar, length is 100.

pic: Picture storage address, type is varchar, length is 100.

<?php
// 創(chuàng)建連接
$conn = new mysqli("localhost", "uesename", "password","test");
// 檢測連接
if ($conn->connect_error) 
{    
die("連接失敗: " . $conn->connect_error);
} 
// 使用 sql 創(chuàng)建數(shù)據(jù)表
$sql = "CREATE TABLE img (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(100) NOT NULL,
pic VARCHAR(200) NOT NULL,)ENGINE=InnoDB DEFAULT CHARSET=utf8 ";
if ($conn->query($sql) === TRUE) 
{    
echo "Table MyGuests created successfully";
} else {    
echo "創(chuàng)建數(shù)據(jù)表錯誤: " . $conn->error;
}
$conn->close(); 
?>

Of course, you can also directly create databases and tables through phpMyAdmin.

For details, please refer to our PHP development user login module tutorial on creating databases and tables.

Continuing Learning
||
<?php // 創(chuàng)建連接 $conn = new mysqli("localhost", "uesename", "password","test"); // 檢測連接 if ($conn->connect_error) { die("連接失敗: " . $conn->connect_error); } // 使用 sql 創(chuàng)建數(shù)據(jù)表 $sql = "CREATE TABLE img ( id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, pic VARCHAR(200) NOT NULL,)ENGINE=InnoDB DEFAULT CHARSET=utf8 "; if ($conn->query($sql) === TRUE) { echo "Table MyGuests created successfully"; } else { echo "創(chuàng)建數(shù)據(jù)表錯誤: " . $conn->error; } $conn->close(); ?>
submitReset Code