What potential pitfalls should be avoided when establishing a connection to a MySQL database in PHP, as demonstrated in the provided script?

One potential pitfall when establishing a connection to a MySQL database in PHP is not handling errors properly. It is important to check for connection errors and handle them gracefully to prevent exposing sensitive information or causing unexpected behavior.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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

echo "Connected successfully";
?>