CHAPTER 6 – Mysql – Multi Statements
The mysqli extension enables you to send multiple SQL statements in one function call by using mysqli_multi_query. The query string contains one or more SQL statements that are divided by a semicolon at the end of each state- ment. Retrieving result sets from multi statements is a little bit tricky, as the following example demonstrates: <?php $conn = mysqli_connect("localhost", "test", "", "world"); $query = "SELECT Name FROM City"; $query .= "SELECT Country FROM Country"; if ($conn->multi_query($query)) { do { if ($result = $mysqli->store_result()) { while ($row = $result->fetch_row()) { printf("Col: %sn", $row[0]; } $result->close(); } } while ($conn->next_result()); } $conn->close();