What are potential pitfalls when trying to access a database in XAMPP using PHP?

One potential pitfall when trying to access a database in XAMPP using PHP is not properly configuring the database connection parameters such as host, username, password, and database name. To solve this issue, ensure that the connection parameters are correctly set in the PHP code.

<?php
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'your_database_name';

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

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