What are the common pitfalls to avoid when writing PHP scripts that interact with MySQL databases?

One common pitfall to avoid when writing PHP scripts that interact with MySQL databases is not properly sanitizing user input, which can lead to SQL injection attacks. To prevent this, always use prepared statements or parameterized queries when executing SQL queries.

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