Create MySQL Database Using PHP

Object-Oriented

<?php
$servername = "localhost";
$username = "root"; // when you work in your computer then use username name "root"
$password = ""; // when you work in your computer then use password Empty
// In this Line Create connection Object-oriented
$conn = new mysqli($servername, $username, $password);
// In this Line  Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
// In this Line  Create database
$sql = "CREATE DATABASE myDataBase";
if ($conn->query($sql) === TRUE) {
    echo "Database has been created successfully";
} else {
    echo "Database has not been creating database: " . $conn->error;
}
$conn->close();
?>

Procedural

<?php 
$servername = "localhost";
$username = "root"; // when you work in your computer then use username name "root"
$password = ""; // when you work in your computer then use password Empty

// In this Line  Create connection Procedural
$conn = mysqli_connect($servername, $username, $password);
// In this Line  Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
// In this Line  Create database
$sql = "CREATE DATABASE myDataBase";
if (mysqli_query($conn, $sql) or die(mysqli_error($conn))) {
    echo "Database has been created successfully";
} else {
    echo "Database has not been creating database: " ;
}
mysqli_close($conn);
?>