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

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 extension or PDO (PHP Data Objects) for improved security, performance, and flexibility in database interactions.

// Using mysqli extension
$mysqli = new mysqli('localhost', 'username', 'password', 'database_name');
if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

// Using PDO
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);