Kmspico Download | Official KMS Activator Website [New Version 2024] Fast and Easy Converter YouTube to MP3 Online KMSAuto Net Activator Download 2024 Immediate Byte Pro Neoprofit AI Blacksprut without borders. Discover new shopping opportunities here where each link is an entrance to a world ruled by anonymity and freedom.

How to Create Database Using Mysqli or PDO in PHP?

More than one MySQL databases are also created in PHP.MySQL Database; The ‘CREATE DATABASE database_name’ statement is used to create.

Creat Database using MySQLi

Code :

<?php
$server = "localhost";
$user = "root";
$password = "";
$conn = mysqli_connect($server, $user, $password);
if($conn){
echo "Connected successfully.";
}
else{
echo "Connection failed : ".mysqli_connect_error();
}
$createdb = "CREATE DATABASE expertstutorial";
if (mysqli_query($conn, $createdb)) {
echo "Database Created successfully.";
} else {
echo "database Creation failed : " . mysqli_error($conn);
}
mysqli_close($conn);
?>

Creating Database using PDO

code:

<?php
$server   = 'localhost';
$user     = 'root';
$password = '';
try{
$conn = new PDO("mysql:host=$server;", $user, $password);
echo "Connected successfully.";
$createdb = "CREATE DATABASE expertstutorial";
$conn->exec($createdb);
echo "Database Created successfully";
}
catch(PDOException $e){
echo "Connection failed : " . $e->getMessage();
}
$conn = null;
?>