query(" set names 'u"/> query(" set names 'u">

Home  >  Article  >  Database  >  mysqli multiple sql statement query

mysqli multiple sql statement query

怪我咯
怪我咯Original
2017-03-31 10:13:351863browse

mysqli has many advantages over mysql. It is recommended that you use it. If you don’t understand it, you can check out the basic tutorial of mysql:
mysqliConnect to the database and use mysqli preprocessing prepare. Not only that, mysqli also supports multi-query features. Look at the following php code:

<?php 
$mysqli = new mysqli("localhost","root","","new");
$mysqli->query("set names &#39;utf8");
//多条sql语句
$sql = "select id,name from `user`;";
$sql .= "select id,mail from `user`";
echo $sql;
if ($mysqli->multi_query($sql)){//multi_query()执行一条或多条sql语句
	do{
		if ($rs = $mysqli->store_result()){//store_result()方法获取第一条sql语句查询结果
			while ($row=$rs->fetch_row()){
				var_dump($row);
				echo "<br>";
			}
			$rs->Close(); //关闭结果集
			if ($mysqli->more_results()){  //判断是否还有更多结果集
				echo "<hr>";
			}
		}
	}while($mysqli->next_result());//next_result()方法获取下一结果集,返回bool值
}
$mysqli->close();  //关闭数据库连接
?>

Regarding some of the methods used, I have annotated very clearly. Special attention should be paid to the fact that multi_query() executes multiple Statements are separated by ;, otherwise an error will occur


The above is the detailed content of mysqli multiple sql statement query. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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