What could be causing the "Access denied for user ''@'localhost'" error in a MySQL query in PHP?

The "Access denied for user ''@'localhost'" error in a MySQL query in PHP is likely caused by incorrect database credentials being used in the connection. To solve this issue, make sure that the username and password provided in the connection string are correct and have the necessary permissions to access the database.

<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_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";
?>