What are the potential security risks associated with 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 can be directly concatenated into SQL queries, allowing malicious users to manipulate the queries and potentially access or modify sensitive data in the database.

// Using prepared statements to prevent SQL injection
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username');
$stmt->execute(['username' => $username]);
$results = $stmt->fetchAll();