The CREATE DATABASE statement is used to create database. (Note: Before creating database you must first connect with database server).Here is an example to create database using PHP:

<?php 
$server_name = "localhost";
$uname = "username";
$pass= "password";
$connection = new mysqli($server_name, $uname, $pass); // connecting with database server // Check connection
if ($connection->connect_error)
{
    die("Connection failed: " . $connection->connect_error);
}
// Create database
if ($connection->query("CREATE DATABASE first_db") === TRUE)
 {     echo "Database created successfully";
 }
else
 {
    echo "Error creating database: " . $connection->error;
 }
$connection->close(); // It will close the connection
?>
  Modified On Mar-15-2018 07:04:35 AM

Leave Comment