How can SQL injection vulnerabilities be mitigated when executing multiple queries in PHP?

SQL injection vulnerabilities when executing multiple queries in PHP can be mitigated by using prepared statements with parameterized queries. This approach helps to separate SQL code from user input, preventing malicious input from being executed as SQL commands.

// Establish a database connection
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL query with placeholders
$stmt = $pdo->prepare('SELECT * FROM users WHERE username = :username AND password = :password');

// Bind parameters to placeholders
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);

// Execute the query
$stmt->execute();

// Fetch the results
$results = $stmt->fetchAll();