首页 ? PHP ? mysqli方法multi_query使用详解(Commands out of sync; you cant run this command now解决办法)

mysqli方法multi_query使用详解(Commands out of sync; you cant run this command now解决办法)

添加评论 次下载365游戏棋牌游戏_365棋牌辅助透视好用吗_365手游棋牌免费送金币

【提示】 非法信息举报请联系本站小编 QQ:5.4069748.5

使用mysqli的multi_query方法时,需要注意,在使用之前,不可以有未使用的结果集。


Multiple?statements?or?multi?queries?must?be?executed???with?mysqli_multi_query().?The?individual?statements
of?the?statement?string?are?separated?by?semicolon.???Then,?all?result?sets?returned?by?the?executed?statements?must?be?fetched.


代码说话:


$sql?=?"SELECT?*?FROM?adminuser_bak?where?adminid?=?347;";
$sql?.=?"SELECT?*?FROM?adminuser_bak?where?adminid?=?348;";
$sql?.=?"SELECT?*?FROM?adminuser_bak?where?adminid?=?349;";
if(!$mysqli->multi_query($sql)){
????echo?"Multi?query?failed?#1:?("?.?$mysqli->errno?.?")?"?.?$mysqli->error;
}else{
????do?{
????????if?($res?=?$mysqli->store_result())?{
???????????/*?var_dump($res->fetch_all(MYSQLI_ASSOC));*/
????????????/*$res->free();*/
????????}
????}?while?($mysqli->more_results()?&&?$mysqli->next_result());
}


必须把results全都从内存中读取出来,才可以再次使用multi_query方法,否则将会得到如下错误:


Commands out of sync; you can't run this command now