how do I loop through the results to know which queries succeeded and
which failed?
int mysqli_stmt_affected_rows ( mysqli_stmt $stmt )
and
bool mysqli_next_result ( mysqli $link ) are the 2 functions you're looking for.
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
$query = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
/* execute multi query */
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s
", $row[0]);
}
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
printf("-----------------
");
}
} while ($mysqli->next_result());
}
/* close connection */
$mysqli->close();
?>
From the documentation.
If you wan to use procedural style, check the example in the documentation. You just have to use mysqli_more_results
or $mysqli->next_result()
to switch between various queries.