To learn more about SQL, please visit our SQL Tutorial.
We must add the CREATE table declaration, mysql_query () function to execute the command.
For example
The following example creates a table named "People," with three columns. The column name will be "first name", "surname" and "age":
<?php
$con = mysql_connect ("localhost", "Peter", "abc123");
if (! $con)
{
die (' Could not connect: '. Mysql_error ());
}
Create Database
if (mysql_query ("CREATE Database my_db, $con)"
{
echo "database created";
}
else
{
echo "Error Creating Database:". Mysql_error ();
}
Create table
mysql_select_db ("my_db", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar (),
LastName varchar (), age
int
)";
Execute Query
mysql_query ($sql, $con);
Mysql_close ($con);
? >
For example
$sql = "CREATE TABLE Persons
(
personID int not NULL auto_increment,
PRIMARY KEY (PersonID),
FirstName VA Rchar (),
LastName varchar (), age
int
) ";
mysql_query ($sql, $con);