In what ways can the code snippet be optimized for better performance and security in PHP development?

Issue: The code snippet is vulnerable to SQL injection attacks due to directly concatenating user input into the SQL query. To optimize for better performance and security, we should use prepared statements with parameterized queries to prevent SQL injection attacks.

// Fix: Use prepared statements with parameterized queries to prevent SQL injection attacks
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username AND password = :password");
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->execute();