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:

connect_error) { die("连接失败: " . $conn->connect_error);} // 创建数据库 $sql = "CREATE DATABASE test"; if ($conn->query($sql) === TRUE) { echo "数据库创建成功"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>

Then we need to create a database img table, containingthree 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.

connect_error) { die("连接失败: " . $conn->connect_error); } // 使用 sql 创建数据表 $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 "创建数据表错误: " . $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
||
connect_error) { die("连接失败: " . $conn->connect_error); } // 使用 sql 创建数据表 $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 "创建数据表错误: " . $conn->error; } $conn->close(); ?>
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!