PHP development to create databases and data tables

After introducing the code, let’s talk about the creation of databases and data tables.

For ease of use, the names we define when creating databases and data tables should be as close or identical to the functions as possible.

##Field description id number username title content reply time
Field name id name title content reply time
Field type int varchar varchar text text datetime
Field length 10 30 30


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

The above is the database creation statement to create a database called message.

The next step is to create the data table, including the field names. Of course, the names should be the same as the functions:

In this way, the database is built, and you can connect to the database and operate it.

Of course, you can also directly enter the database creation.

Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!