In what situations can the use of PHP variables in SQL queries lead to database performance issues?

Using PHP variables directly in SQL queries can lead to database performance issues when it leaves the application vulnerable to SQL injection attacks or when it results in inefficient query execution plans. To avoid these issues, it is recommended to use prepared statements with parameterized queries in PHP to safely pass variables to the database.

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