In the context of PHP development, what are the best practices for handling deprecated features like the mysql extension?

The mysql extension in PHP has been deprecated since PHP 5.5 and removed in PHP 7. To handle this, it is recommended to switch to either the mysqli or PDO extension for database operations. This ensures compatibility with newer PHP versions and improves security.

// Using mysqli extension to connect to a MySQL database
$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";