The CREATE DATABASE statement is used to create a database in MySQL.
CREATE DATABASE database_name
To get PHP to execute the SQL instructions, first you must create a mysqli object with the
connection to the server, then use the query() method of the MySQLi class.
mysqliObj->query($sql_query)
- mysqliObj - is the mysqli object created with new mysqli()
- $sql_query - is a string with SQL instructions. This method sends a query or command to a MySQL connection, will return a result object, or TRUE on success. FALSE on failure.
The following example creates a database called "tests":
<?php
// connect to the MySQL server
$conn = new mysqli('localhost', 'root', 'pass');
// check connection
if (mysqli_connect_errno()) {
exit('Connect failed: '. mysqli_connect_error());
}
// sql query with CREATE DATABASE
$sql = "CREATE DATABASE `tests` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
// Performs the $sql query on the server to create the database
if ($conn->query($sql) === TRUE) {
echo 'Database "tests" successfully created';
}
else {
echo 'Error: '. $conn->error;
}
$conn->close();
?>
Check this link http://coursesweb.net/php-mysql/php-mysql-using-mysqli