How to Create a MySQL Database from PHP?
<?php
$servername = "localhost";
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection$conn = new mysqli($servername, $username, $password);
// Create connection$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Create database$sql = "CREATE DATABASE databasename";
die("Connection failed: " . $conn->connect_error);
}
// Create database$sql = "CREATE DATABASE databasename";
if ($conn->query($sql) === TRUE)
{
echo "Database created successfully";
}
echo "Database created successfully";
}
else
{
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
0 Comments