How can SQL injection vulnerabilities be mitigated in PHP code?

SQL injection vulnerabilities can be mitigated in PHP code by using prepared statements with parameterized queries. This approach separates the SQL query logic from the user input, preventing malicious SQL code from being injected into the query.

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