我有两个查询,我必须运行:
我试图从第一个结果中得到结果,所以我可以运行第二个,但唯一的方法,我可以做到这一点没有得到这个错误:
不同步的命令; 你现在不能运行这个命令
是closuresmysqli连接并重新创build它。
这是我的代码的本质:
// The $sql is to run a stored procedure. I omitted that code // because it's very lengthy, but it works perfectly every time. // The stored procedure is basically a recursive SELECT query to // pull hierarchical data from a self-referencing data set. $res = mysqli_query($mysqli, $sql); // Build a comma-delimited list of id numbers $ids = ""; $i = 0; $qty = mysqli_num_rows($res); while ($recs = mysqli_fetch_array($res)) { $i += 1; $ids .= $recs["data_id"]; if ($i < $qty) $ids .= ", "; } mysqli_free_result($res); // Close connection to MySQL (Remove this & connect statement below causes it to fail) mysqli_close($mysqli); // Re-open connection to MySQL (Remove this & close statement above causes it to fail) $mysqli = connect_DB(); $sql = "UPDATE data SET data_val = data_val + ".$val." WHERE data_id IN (".$ids.")"; $res = mysqli_query($mysqli, $sql);
我试过每一个build议,我发现(包括从十几个从stackoverflowpost),但没有任何工作。 我错过了什么? 这肯定是不合理的,特别是考虑到我可以通过使用“free_result”语句连续运行其他查询。
这是由于命令不同步的已知“内部SQL错误”引起的。 因此连接必须关闭并重新打开以使命令重新同步。
用户注释参考: http : //php.net/manual/en/mysqli-result.free.php