What are some common pitfalls to avoid when working with PDO in PHP for database operations?

One common pitfall to avoid when working with PDO in PHP for database operations is not properly handling errors. Make sure to set PDO error mode to exception to catch any errors that may occur during database operations.

// Set PDO error mode to exception
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
```

Another common pitfall is not using prepared statements, which can leave your code vulnerable to SQL injection attacks. Always use prepared statements to securely execute SQL queries.

```php
// Using prepared statements
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
```

Additionally, remember to properly sanitize user input before using it in SQL queries to prevent SQL injection attacks.

```php
// Sanitize user input
$username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);