What are the advantages and disadvantages of using PDO over MySQLi for database connections in PHP, especially in the context of object-oriented programming?

When comparing PDO and MySQLi for database connections in PHP, PDO is often preferred for its flexibility and support for multiple database systems, while MySQLi is more specific to MySQL. In the context of object-oriented programming, PDO is also easier to work with due to its object-oriented approach, making it more suitable for modern PHP applications. However, MySQLi may offer slightly better performance in some cases due to its closer integration with MySQL.

// Using PDO for database connection in PHP

try {
    $pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}