mysqli_more_results()函數(shù)檢查批量查詢中是否還有查詢結(jié)果
檢查上一次調(diào)用 mysqli_multi_query() 函數(shù)之后, 是否還有更多的查詢結(jié)果集。
mysqli_more_results($con)
| 序號 | 參數(shù)及說明 |
|---|---|
| 1 | con(必需) 這是一個表示與MySQL Server的連接的對象。 |
如果上一次調(diào)用 mysqli_multi_query() 函數(shù)之后, 還有更多的結(jié)果集可以讀取,返回 TRUE,否則返回 FALSE。
此函數(shù)最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
以下示例演示了mysqli_more_results()函數(shù)的用法(面向過程風(fēng)格)-
<?php
//建立連接
$con = mysqli_connect("localhost", "root", "password", "test");
//執(zhí)行多個查詢
$query = "SELECT * FROM players;SELECT * FROM emp";
mysqli_multi_query($con, $query);
do{
$result = mysqli_use_result($con);
while($row = mysqli_fetch_row($result)){
print("Name: ".$row[0]."\n");
print("Age: ".$row[1]."\n");
print("\n");
}
if(mysqli_more_results($con)){
print("::::::::::::::::::::::::::::::\n");
}
}while(mysqli_next_result($con));
mysqli_close($con);
?>輸出結(jié)果
Name: Dhavan Age: 33 Name: Rohit Age: 28 Name: Kohli Age: 25 :::::::::::::::::::::::::::::: Name: Raju Age: 25 Name: Rahman Age: 30 Name: Ramani Age: 22
在面向?qū)ο蟮臉邮街?,此函?shù)的語法為$con-> more_results();。以下是面向?qū)ο髽邮街写撕瘮?shù)的示例;
<?php
$con = new mysqli("localhost", "root", "password", "test");
//多查詢
$res = $con->multi_query("SELECT * FROM players;SELECT * FROM emp");
do {
$result = $con->use_result();
while($row = $result->fetch_row()){
print("Name: ".$row[0]."\n");
print("Age: ".$row[1]."\n");
print("\n");
}
if($con->more_results()){
print("::::::::::::::::::::::::::::::\n");
}
} while ($con->next_result());
//關(guān)閉連接
$res = $con -> close();
?>輸出結(jié)果
Name: Dhavan Age: 33 Name: Rohit Age: 28 Name: Kohli Age: 25 :::::::::::::::::::::::::::::: Name: Raju Age: 25 Name: Rahman Age: 30 Name: Ramani Age: 22