韩顺平php使用mysqli的mysqi::multi_query() 一次性查询并显示多表结构和内容

<?php
//1.得到musqli对象
$mysqli=new MYSQLi("localhost","root","hsp123","test");
//2.批量查询
$sqls="select*from emp";
$sqls.="select*from user1";
//3.处理结果
//如果成功,则至少有一个结果集
if($res=$mysqli->query($sqls)){
do{
	//从我们mysqli连接取出第一个结果集store_result()
	$result=$mysqli->store_result();
	//显示mysqli result 对象
     while($row=mysqli->fetch_row()){
	  foreach($row as $key=>$val){
	   echo "--$val";
	  }
	  echo "<br/>";
	 
	 }
	 //及时的释放$result
	 $result->free();
	 if(!$mysqli->more_result()){//more_result()判断下面是否还有结果集返回一个bool值
		 break;
	 }
	 echo "<br/>********新的结果集*********<br>";

}while($mysql->next_result());//$mysql->next_result()这个函数比较弱 返回下一个结果集

}

//4.关闭资源
$mysqli->close();
?>

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43345480/article/details/89712920