What are the potential pitfalls to avoid when working with PHP and SQL databases?

One potential pitfall to avoid when working with PHP and SQL databases is SQL injection attacks. To prevent this, always use prepared statements or parameterized queries to sanitize user input and prevent malicious SQL code from being executed.

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