What are the potential pitfalls of using prepared statements incorrectly in PHP for database queries?

Potential pitfalls of using prepared statements incorrectly in PHP for database queries include SQL injection attacks, data integrity issues, and performance degradation. To avoid these pitfalls, always ensure that user input is properly sanitized and bound to parameters in prepared statements.

// Correct way to use prepared statements in PHP for database queries
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll();