query
function to get PHP to execute the SQL statements:
DROP TABLE
statement, used to remove a database table, and
CREATE TABLE
statement, used to create a table in MySQL.
query
is used to send a query or command to a MySQL connection.
A database must be selected before a table can be dropped or created.
The database is selected with the mysqli
function with one more parameter.
The following example drops and creates a table using the following SQL commands:
DROP TABLE CDs; CREATE TABLE CDs ( ASIN CHAR(10) PRIMARY KEY, Title VARCHAR(32) NOT NULL, price REAL CHECK( price > 0.0 ) ); |
VARCHAR
, you must specify the maximum length of the field, e.g. VARCHAR(15)
.
The CREATE TABLE
statement is complicated.
For further studies,
My mother made us eat all sorts of vitamins and supplements. One day I nearly choked on part of The Sunday Times. — Milton Jones |