<?php
$mysqli = new mysqli("localhost","root","root","world");
$query = "SELECT Name FROM City;";
$query .= "SELECT Name FROM Country;";
if($mysqli->multi_query($query)){
do{
if($result = $mysqli->store_result()){
while($row = $result->fetch_row()){
printf("Col: %s<br />", $row[0]);
}
$result->close();
}
echo "<hr />";
} while ($mysqli->more_results() && $mysqli->next_result());
}
$mysqli->close();
注意while条件的写法while ($mysqli->more_results() && $mysqli->next_result()),按书中的写法会报错.
PHP MySQL多重语句的样板代码
最新推荐文章于 2022-05-28 15:20:50 发布
本文演示了如何使用PHP和mysqli扩展执行多个MySQL查询,包括从City和Country表中选择名称。通过while循环和mysqli的multi_query, store_result, fetch_row等方法,实现了数据的有效检索和展示。
4440

被折叠的 条评论
为什么被折叠?



