What are common pitfalls when using MySQL functions in PHP?

One common pitfall when using MySQL functions in PHP is not properly escaping user input, leaving the application vulnerable to SQL injection attacks. To solve this, always use prepared statements or parameterized queries to sanitize user input before executing SQL queries.

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