Create MySQL Database Using PHP
Object-Oriented
<?php
$servername = "localhost";
$username = "root"; // when you work in your computer then use username name "root"
$password = ""; // when you work in your computer then use password Empty
// In this Line Create connection Object-oriented
$conn = new mysqli($servername, $username, $password);
// In this Line Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// In this Line Create database
$sql = "CREATE DATABASE myDataBase";
if ($conn->query($sql) === TRUE) {
echo "Database has been created successfully";
} else {
echo "Database has not been creating database: " . $conn->error;
}
$conn->close();
?>
Procedural
<?php
$servername = "localhost";
$username = "root"; // when you work in your computer then use username name "root"
$password = ""; // when you work in your computer then use password Empty
// In this Line Create connection Procedural
$conn = mysqli_connect($servername, $username, $password);
// In this Line Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// In this Line Create database
$sql = "CREATE DATABASE myDataBase";
if (mysqli_query($conn, $sql) or die(mysqli_error($conn))) {
echo "Database has been created successfully";
} else {
echo "Database has not been creating database: " ;
}
mysqli_close($conn);
?>
Quick ask your Question
- Connect mysql database using php Language
- Insert record into MySQL Database Using PHP Language
- Get Record from MySQL Database in PHP
- Update Record from MySQL Database in PHP
- Delete Record From a MySQL Database using PHP
- Insert Multiple Records into MySQL with a Single Query
- Create MySQL Database Using PHP
- Create Table in MySQL Database Using PHP