Are there any common pitfalls to avoid when testing MySQL/PHP connections locally?

One common pitfall to avoid when testing MySQL/PHP connections locally is not properly handling connection errors. It's important to check for errors when establishing a connection to the database and handle them appropriately to prevent unexpected behavior in your application.

<?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";
?>