What are the advantages of using PDO over the deprecated mysql_* functions for database operations in PHP?

The mysql_* functions in PHP have been deprecated since PHP 5.5 and removed in PHP 7. Instead, it is recommended to use PDO (PHP Data Objects) for database operations due to its improved security, flexibility, and support for multiple database systems.

// Using PDO for database operations
try {
    $pdo = new PDO('mysql:host=localhost;dbname=my_database', 'username', 'password');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Perform database operations here
    
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}