当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


PHP mysqli_more_results()用法及代码示例


定义和用法

这个mysqli_more_results()函数验证上次执行的多查询中是否有更多结果。

用法

mysqli_more_results($con)

参数

Sr.No 参数及说明
1

con(Mandatory)

这是一个表示与 MySQL 服务器的连接的对象。

返回值

如果有更多结果集(或错误),则 mysqli_more_results() 函数返回 true,如果没有更多结果集,则返回 false。

PHP版本

这个函数最初是在 PHP 版本 5 中引入的,适用于所有后续版本。

示例

以下示例演示了 mysqli_more_results() 函数的用法(程序风格) -

<?php
   //Creating a connection
   $con = mysqli_connect("localhost", "root", "password", "test");

   //Executing the multi query
   $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);
?>

这将产生以下结果 -

Name:Dhavan
Age:33

Name:Rohit
Age:28

Name:Kohli
Age:25

::::::::::::::::::::::::::::::
Name:Raju
Age:25

Name:Rahman
Age:30

Name:Ramani
Age:22

示例

在面向对象的风格中,这个函数的语法是 $con->more_results();以下是面向对象样式 $minus 中此函数的示例;

<?php
   $con = new mysqli("localhost", "root", "password", "test");

   //Multi query
   $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());

   //Closing the connection
   $res = $con -> close();
?>

这将产生以下结果 -

Name:Dhavan
Age:33

Name:Rohit
Age:28

Name:Kohli
Age:25

::::::::::::::::::::::::::::::
Name:Raju
Age:25

Name:Rahman
Age:30

Name:Ramani
Age:22

相关用法


注:本文由纯净天空筛选整理自 PHP mysqli_more_results() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。