PHP mysqli_next_result()Functions
Execute multiple queries against the database. Use the mysqli_next_result() function to prepare the next result set:
<?php
// 假定数据库用户名:root,密码:123456,数据库:EXAMPLE
$con=mysqli_connect("localhost","root","123456","EXAMPLE");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
$sql = "SELECT name FROM websites ORDER BY alexa;";
$sql .= "SELECT app_name FROM apps";
// 执行多个查询
if (mysqli_multi_query($con,$sql))
{
do
{
// 存储第一个结果集
if ($result=mysqli_store_result($con))
{
while ($row=mysqli_fetch_row($result))
{
printf("%s",$row[0]);
echo "<br>";
}
}
} while (mysqli_next_result($con));
}
mysqli_close($con);
?>
Definition and Usage
The mysqli_next_result() function is tomysqli_multi_query()prepare the next result set.
Syntax
mysqli_next_result(connection);
| Parameters | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
Technical Details
| Return value: | Returns TRUE on success, or FALSE on failure. |
|---|---|
| PHP Version: | 5+ |
PHP MySQLi Reference Manual Other Extensions