What are the potential risks of not using prepared statements in PHP when interacting with a database?

Using prepared statements in PHP when interacting with a database helps prevent SQL injection attacks by separating SQL code from user input. Without prepared statements, user input could be directly concatenated into SQL queries, making it vulnerable to malicious input that could alter the query's logic or access unauthorized data.

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