<?Php
require "config.php"; // Database connection string

We can create database in mysql server by using mysql_create_db function. If sufficient permission is there for the user then this function will create the database in MySQL Server. Let us try with this simple example for creating a database.

$link=mysql_connect ("$servername","$dbusername","$dbpassword")
or die ( " Not able to connect to server ");

?>

The above code will create database in PHP 5. Note that inside the query to create database we have used IF NOT EXISTS , so there will not be any error message if database is already exist and we are trying to create with same name. Without the clause IF NOT EXISTS we will get error message if we try to create a database which is already exists.