When using PDO for database access in PHP, what are the advantages and disadvantages compared to using a custom ORM like Doctrine or Propel?

When using PDO for database access in PHP, the advantages include its simplicity, flexibility, and compatibility with different database systems. However, using a custom ORM like Doctrine or Propel can provide additional features such as automatic mapping of database tables to PHP objects, query building helpers, and advanced caching mechanisms. The disadvantage of using a custom ORM is the added complexity and learning curve compared to using PDO directly.

// Using PDO for database access
$dsn = 'mysql:host=localhost;dbname=mydatabase';
$username = 'username';
$password = 'password';

try {
    $pdo = new PDO($dsn, $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // Perform database operations using $pdo
    
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}