PHP Create Table In MySQL


After Creating Database we have to create table to store the data for that we have to run below script.
<?php

include('config.php');
// sql to create table $sql = "CREATE TABLE Your_table_name(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)"
;

if ($conn->query($sql) === TRUE) 

{
    echo "Table MyGuests created successfully";
} 

else 
{
    echo "Error creating table: " . $conn->error;
}


?>
Note: Don't forget to add connection string into your file. 

0 Comments