English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
mysqli_more_results()函数检查批量查询中是否还有查询结果
检查上一次调用 mysqli_multi_query() 函数之后, 是否还有更多的查询结果集。
mysqli_more_results($con)
序号 | 参数及说明 |
---|---|
1 | con(必需) 这是一个表示与MySQL Server的连接的对象。 |
如果上一次调用 mysqli_multi_query() 函数之后, 还有更多的结果集可以读取,返回 TRUE,否则返回 FALSE。
此函数最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
以下示例演示了mysqli_more_results()Function usage (procedural style)-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "test"); //Execute multiple queries $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); ?>
Output result
Name: Dhavan Age: 33 Name: Rohit Age: 28 Name: Kohli Age: 25 :::::::::::::::::::::::::::::: Name: Raju Age: 25 Name: Rahman Age: 30 Name: Ramani Age: 22
In the object-oriented style, the syntax of this function is$con-> more_results();.Here is an example of this function in an object-oriented style;
<?php $con = new mysqli("localhost", "root", "password", "test"); //Multiple queries $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()); //Close connection $res = $con -> close(); ?>
Output result
Name: Dhavan Age: 33 Name: Rohit Age: 28 Name: Kohli Age: 25 :::::::::::::::::::::::::::::: Name: Raju Age: 25 Name: Rahman Age: 30 Name: Ramani Age: 22