[英]In PHP & MySql programming how to executive more then 3 queries in a single statement?
i want to execute a more then 3 queries in a single statement. 我想在一个语句中执行3个以上的查询。 is is possible?
有可能吗?
i need to insert the values into the table select entire table count the users. 我需要将值插入表中,选择整个表来计数用户。
is it possible to do all these in a single statement. 是否可以在单个语句中完成所有这些操作。
Thanks 谢谢
您只能使用mysqli_multi_query()
在mysqli中使用3个以上的查询,但是mysql不支持它。
Example code : 示例代码:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT CURRENT_USER();";
$query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
/* execute multi query */
if ($mysqli->multi_query($query)) {
do {
/* store first result set */
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
$result->free();
}
/* print divider */
if ($mysqli->more_results()) {
printf("-----------------\n");
}
} while ($mysqli->next_result());
}
/* close connection */
$mysqli->close();
?>
Change it accordingly. 相应地更改它。 It shows multiquery in action using mysqli.
它显示了使用mysqli进行操作的多查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.