What potential pitfalls should be avoided when working with MySQL databases in PHP?

One potential pitfall to avoid when working with MySQL databases in PHP is SQL injection attacks. To prevent this, always use prepared statements or parameterized queries to sanitize user input before executing SQL queries.

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