How can the "Client does not support authentication protocol requested by server" warning be resolved in a PHP script?

The warning "Client does not support authentication protocol requested by server" typically occurs when the MySQL server is using an outdated authentication method that is not supported by the PHP script. To resolve this issue, you can update the authentication method used by the MySQL server to a compatible one, such as 'caching_sha2_password'. This can be done by running the following SQL query: ALTER USER 'username'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';

// Connect to MySQL database with updated authentication method
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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