What are some common security risks associated with using MySQL queries in PHP?

One common security risk associated with using MySQL queries in PHP is SQL injection, where malicious SQL statements are inserted into an entry field for execution. To prevent this, developers should use parameterized queries or prepared statements to sanitize user input and prevent SQL injection attacks.

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