Loading...
start the course

Learn PHP

Codes and notes

Create create Table
Back Next

The CREATE DATABASE statement is used to create a database in MySQL.
The following examples create a database named "myDB":

syntax
<?php
$sql ="CREATE DATABASE TABLE [name of table](
//rows and data types

)";

? >

Back Next

Code editor

    <!DOCTYPE html>
    <html>
    <body>

    <?php
    
    # if statement in php
    
   
        
        $sql 
        
        ="CREATE DATABASE TABLE users(
            id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($conn->query($sql) === TRUE) { echo "Table created successfully"; }else { echo "Error creating table: " . $conn->error; $conn->close(); } ?> </body> </html>

Output