What are the potential pitfalls of not using prepared statements when executing database queries in PHP?

Using prepared statements helps prevent SQL injection attacks by separating SQL code from user input. Without prepared statements, user input can be directly concatenated into SQL queries, making it vulnerable to malicious input. To mitigate this risk, always use prepared statements when executing database queries in PHP.

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