What are common pitfalls when using PDO for database connections in PHP?

One common pitfall when using PDO for database connections in PHP is not properly handling exceptions. To solve this, always wrap PDO operations in try-catch blocks to catch any potential errors and handle them appropriately.

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();
}