PDO (PHP data object) enables fast and consistent interface for access across multiple databases.
Advantages of PDO is support for different database drivers, allows a developer to lightly migrate to a different database without any effortless change of code.
Popular databases supported by PDO: MYSQL, IBM, FIREBIRD, CUBRID, INFORMIX, DBLIB, PGSQL, OCI, SQLITE...

Using by SQL instruction the CREATE DATABASE we can create a database in MySQL.


An example creating a MySQL database called a "test" with PDO

<?php

try{
    
$pdo = new PDO("mysql:host=localhost;""your username""your password");
    
// Set the PDO error mode to exception
    
$pdo->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
} catch(
PDOException $e){
    die(
"ERROR: Could not connect. " $e->getMessage());
}
 
// Attempt create database query execution
try{
    
$sql "CREATE DATABASE test";
    
$pdo->exec($sql);
    echo 
"Database TEST created successfully";
} catch(
PDOException $e){
    die(
"ERROR: Could not able to execute $sql. " $e->getMessage());
}
 
// Close connection
unset($pdo);
?>