What is the correct syntax for creating a new database in MySQL Query Browser using PHP?
To create a new database in MySQL Query Browser using PHP, you can use the following syntax:
<?php
$servername = "localhost";
$username = "username";
$password = "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 dbname";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
Keywords
Related Questions
- What are some recommended resources for learning more about PHP conditional statements like if-else?
- How can developers troubleshoot and debug PHP code that is throwing errors related to file uploads, like the "Permission denied" warning in the provided example?
- How can PHP be used to limit the number of entries displayed on a page, such as in a guestbook?