How can the use of deprecated MySQL extension in PHP affect the functionality of the code snippet?
Using deprecated MySQL extension in PHP can affect the functionality of the code snippet as it is no longer supported in newer versions of PHP. This can lead to security vulnerabilities, compatibility issues, and potential errors in the code. To solve this issue, it is recommended to switch to MySQLi or PDO extensions for database connectivity in PHP.
// Using MySQLi extension for database connectivity
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "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";