What are common challenges faced by PHP beginners when trying to create databases in MySQL?

One common challenge faced by PHP beginners when trying to create databases in MySQL is not properly establishing a connection to the database server. This can be solved by using the mysqli_connect function to connect to the MySQL server before attempting to create or interact with databases.

// Establishing a connection to the MySQL server
$servername = "localhost";
$username = "username";
$password = "password";

$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";