What are the common security risks associated with PHP programming and how can they be mitigated?

One common security risk in PHP programming is SQL injection, where attackers can manipulate SQL queries by inserting malicious code. This can be mitigated by using prepared statements with parameterized queries to sanitize user input.

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