Let's do an SQL query using the CREATE DATABASE, after that, We will execute this SQL query by passing it to the PHP mysqli_query () function to finally create our database.
Let's connect to DB and create myblog table look following example:
#example.php
<?php
/* connect to db */
$link = mysqli_connect("localhost", "root", "");
// Check connection
if ($link === false) {
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt create database query execution
$sql = "CREATE DATABASE myblog";
if (mysqli_query($link, $sql)) {
echo "Database created successfully";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>