PHP MySQL creates database

The database has one or more tables.

Create database

CREATEDATABASEstatement is used to create a database in MySQL.

Syntax

CREATEDATABASEdatabase_name

Category Detailed explanation
Basic syntax create database database name;
Example create database liwenkai;
Example description Create a database, the name of the database is liwenkai

In order for PHP to execute the above statement, we must use the mysql_query() function. This function is used to send a query or command to the MySQL connection.


Rules for creating a database:

1. Cannot be used with other databases Duplicate name, otherwise an error will occur.

2. The name can be composed of any letters, Arabic numerals, underscores (_), and "$". It can start with any of the above characters, but it cannot use numbers alone, otherwise it will be confused with the numerical value.

3. You cannot use the MYSQL keyword as the database name or table name.

4. By default, the database name under Windows is not sensitive. The opposite is true under Linux, so in order to facilitate database transplantation between platforms, it is recommended to use lowercase to define database names and table names.


Example

A database named "myDB" is created in the following example:

Program running result:

Database created successfully


Delete database

Note:
drop is Chinese and can be translated as falling down, not wanting anymore

database It is refers to the library

# 是 The name of the library refers Example


Program run results:

# [Remember] Note

: After the database is deleted, all the following data will be deleted, so you must be careful and corresponding before deleting Backup.

Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
## Basic syntax ## Example drop database liwenkai; Example description Delete a database, the name of the database is liwenkai steer in the example below deletes a database called "MyDB":
#Database deletion is successful
## Category Detailed explanation
drop database library name;