PHP mysqli_next_result() 函数
2018-12-08 17:19 更新
PHP mysqli_next_result() 函数
实例
执行多个针对数据库的查询。请使用 mysqli_next_result() 函数来准备下一个结果集:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT Lastname FROM Persons ORDER BY LastName;";
$sql .= "SELECT Country FROM Customers";
// Execute multi query
if (mysqli_multi_query($con,$sql))
{
do
{
// Store first result set
if ($result=mysqli_store_result($con))
{
while ($row=mysqli_fetch_row($result))
{
printf("%sn",$row[0]);
}
mysqli_free_result($con);
}
}
while (mysqli_next_result($con));
}
mysqli_close($con);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT Lastname FROM Persons ORDER BY LastName;";
$sql .= "SELECT Country FROM Customers";
// Execute multi query
if (mysqli_multi_query($con,$sql))
{
do
{
// Store first result set
if ($result=mysqli_store_result($con))
{
while ($row=mysqli_fetch_row($result))
{
printf("%sn",$row[0]);
}
mysqli_free_result($con);
}
}
while (mysqli_next_result($con));
}
mysqli_close($con);
?>
定义和用法
mysqli_next_result() 函数为 mysqli_multi_query() 准备下一个结果集。
语法
mysqli_next_result(connection);
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
---|---|
PHP 版本: | 5+ |
PHP MySQLi 参考手册
以上内容是否对您有帮助:
更多建议: