简体   繁体   English

如何通过设置变量执行PHP mysqli多查询

[英]How to execute PHP mysqli multi query by setting variables

I want to execute a multi query in PHP MySQL , and get the result.我想在PHP MySQL执行一个多查询,并得到结果。 My queries are like this.我的查询是这样的。

$sql1 = "set @uid:=(select chat_id from chat_notify where online=1 and engaged=0 limit 1);";
$sql1 .= "update chat_notify set engaged=1,emp_id=1 where chat_id=@uid;";
$sql1 .= " select @uid";

$sql = $mysqli->multi_query($sql1);

I want to get the result of the uid in php .我想在php中获得uid的结果。

Change your code accordingly相应地更改您的代码

$sql1 = "set @uid:=(select chat_id from chat_notify where online=1 and engaged=0 limit 1)";
$sql2 = "update chat_notify set engaged=1,emp_id=1 where chat_id=@uid";
$sql3 = "select @uid";

$mysqli->query($sql1);
$mysqli->query($sql2);
$res = $mysqli->query($sql3);

and then get your query result usual way然后以通常的方式获取您的查询结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM