What are the advantages of using mysqli or PDO over the deprecated mysql extension in PHP for database operations?

The deprecated mysql extension in PHP is no longer recommended for database operations due to security vulnerabilities and lack of support. It is advisable to use either the mysqli or PDO extension, which offer better security features, support for prepared statements, and compatibility with newer versions of PHP.

// Using mysqli extension for database operations
$mysqli = new mysqli("localhost", "username", "password", "database");

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Perform database operations here

$mysqli->close();