How does the use of prepared statements impact the execution of multi-line queries in PHP?

When using prepared statements in PHP, multi-line queries can still be executed efficiently without any issues. Prepared statements separate the SQL query from the data, allowing the database to parse and optimize the query just once, regardless of the number of times it is executed. This can improve performance and prevent SQL injection attacks.

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

// Prepare a multi-line query using prepared statements
$stmt = $pdo->prepare('SELECT * FROM users WHERE age > :age AND gender = :gender');

// Bind parameters to the query
$stmt->bindParam(':age', $age, PDO::PARAM_INT);
$stmt->bindParam(':gender', $gender, PDO::PARAM_STR);

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

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

// Loop through the results
foreach ($results as $row) {
    // Process each row
}