What potential pitfalls should I be aware of when working with database queries in PHP?

One potential pitfall when working with database queries in PHP is SQL injection attacks, where malicious SQL code is inserted into input fields to manipulate the database. To prevent this, always use prepared statements with parameterized queries to sanitize user input.

// Example of using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();