PHP mysqli_multi_query() 函数
实例
执行多个针对数据库的查询:
<?php $con=mysqli_connect("localhost","my_user","my_password","my_db"); // 检测链接 if (mysqli_connect_errno($con)) { echo "连接到 MySQL 失败: " . mysqli_connect_error(); } $sql = "SELECT Lastname FROM Persons ORDER BY LastName;"; $sql .= "SELECT Country FROM Customers"; // 执行多个 SQL 语句 if (mysqli_multi_query($con,$sql)) { do { // 存储第一个结果集 if ($result=mysqli_store_result($con)) { while ($row=mysqli_fetch_row($result)) { printf("%sn",$row[0]); } mysqli_free_result($result); } } while (mysqli_next_result($con)); } mysqli_close($con); ?>
定义和用法
mysqli_multi_query() 函数执行一个或多个针对数据库的查询。多个查询用分号进行分隔。