How can a PHP developer handle multiple result sets when querying a database?

When querying a database in PHP, a developer can handle multiple result sets by using the `mysqli_multi_query()` function to execute multiple queries in a single call. This allows the developer to retrieve multiple result sets from the database and process them accordingly.

// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Query to retrieve multiple result sets
$query = "
    SELECT * FROM table1;
    SELECT * FROM table2;
";

// Execute the multi-query
if (mysqli_multi_query($connection, $query)) {
    do {
        if ($result = mysqli_store_result($connection)) {
            while ($row = mysqli_fetch_assoc($result)) {
                // Process the result set
            }
            mysqli_free_result($result);
        }
    } while (mysqli_next_result($connection));
}

// Close the database connection
mysqli_close($connection);