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";
Related Questions
- How can beginners effectively learn PHP basics before attempting complex calculations like age conversion?
- What are some common errors that can lead to a redirection loop in PHP code?
- What are the best practices for ensuring compatibility and functionality of a database across different operating systems in PHP development?