What is the potential cause of the "Access denied for user" warning when using mysql_real_escape_string in PHP?

The "Access denied for user" warning when using mysql_real_escape_string in PHP may be caused by incorrect database credentials or insufficient permissions for the user to access the database. To solve this issue, double-check the database connection details and ensure that the user has the necessary permissions to perform the operation.

<?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);
}

// Escape user input to prevent SQL injection
$escaped_string = $conn->real_escape_string($user_input);

// Close connection
$conn->close();
?>