Home > Backend Development > PHP Tutorial > php中对MYSQL操作之批量执行,与获取批量结果

php中对MYSQL操作之批量执行,与获取批量结果

WBOY
Release: 2016-06-23 13:51:53
Original
982 people have browsed it

<?php //批量执行,与获取结果//创建一个mysqli对象$mysqli = new MySQLi("主机名","mysql用户名","密码","数据库名");//执行批量操作---查询,链接各个sql语句要用;隔开,推荐不要使用*,查什么写什么;$sql = "select * from 表名;";$sql.= "select * from 表名;";$sql.= "select * from 表名";//批量处理并获取结果if($res=$mysqli->multi_query($sql)){	do{		//从$mysqli这个链接中取出一个结果集		$result=$mysqli->store_result();		//取出结果集的数据		while($rows=$result->fetch_row()){			foreach($row as $key=$val){				echo  "$key----$val";			}			echo "<br>";		}		//释放资源		$result->free();		//判断是否下面还有结果集,没有则跳出		if(!$mysqli->more_results()){			break;		}		//取出下一个结果集,		//但next_result()这个方法有缺点就是不能判断下一个结果集是否存在,空它也取出来。	  }while($mysqli->next_result());}//关闭资源,一般情况下链接是系统自己过段时间断开的,这里不是立即断掉$mysqli->close();?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template