What are some common pitfalls when trying to connect to a server using PHP?

One common pitfall when trying to connect to a server using PHP is not specifying the correct host, username, password, or database name in the connection parameters. Make sure to double-check these details before attempting to connect to the server. Additionally, not handling connection errors properly can lead to issues when trying to establish a connection.

<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "my_database";

// Create connection
$conn = new mysqli($host, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>