php - 我得到:命令不同步;你现在不能运行这个命令?
问题描述
我想执行两个查询,我得到“命令不同步;你现在不能运行这个命令”我已经查看了以前关于同一问题的问题,但无法找出解决方案。我知道这是因为我正在运行两个查询。
谁能告诉我我做错了什么?
查询一:
if($_SERVER["REQUEST_METHOD"] == "POST"){
$sql = "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test1', 'AFVENTER TILBUD', 'test1');";
$sql .= "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test2', 'AFVENTER TILBUD', 'test2');";
$sql .= "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test3', 'AFVENTER TILBUD', 'test3')";
if ($link->multi_query($sql) === TRUE) {
查询二:
$sql = "SELECT * FROM offer_requests WHERE username = '" .
($_SESSION["username"]) . "'";
if($result = mysqli_query($link,
$sql)){
if(mysqli_num_rows($result) > 0){
echo "<th></th>";
echo "<th></th>";
echo "<th></th>";
echo "</tr>";
while($row =
mysqli_fetch_array($result)){
echo "<tr>";
echo "<th
class='hidden'>" . $row['uniqid'] . "</th>";
echo "<th>" .
$row['car'] . "</th>";
echo "<th>" .
$row['l_comp_one'] . "</th>";
echo "<th>" .
$row['l_comp_two'] . "</th>";
echo "<th>" .
$row['l_comp_three'] . "</th>";
echo "<th>";
echo "<a
href='read_request.php?uniqid=". $row['uniqid'] ."' title='Se
tilbudsanmodning' data-toggle='tooltip'><span class='glyphicon
glyphicon-eye-open'></span></a>";
echo "</th>";
echo "</tr>";
}
// Free result set
mysqli_free_result($result);
} else{
echo "</br></br><p><b><i>Ingen
informationer fundet.</i></b></p>";
}
} else{
echo "ERROR: Was not able to
execute $sql. " . mysqli_error($link);
}
echo "</tbody>";
echo "</table>";
解决方案
如果我正确理解了另一个答案,这就是要做的事情:
if ($link->multi_query($sql) === TRUE) {
// the loop below is the fix. It just cycles through the results, ignoring them
while(mysqli_more_results($link)) {
mysqli_next_result($link);
// or $link->next_result();
}
//...
推荐阅读
- ios - Swift - 内部具有水平堆栈视图的单元格表视图包含不同的文本 - 自动高度
- qemu - 如何像 gdbserver --multi 一样从 GDB 存根重新启动 QEMU 用户模式程序?
- java - 将片段的列表视图的单击项添加到另一个片段的列表视图
- c# - Xamarin Edittext = true 然后不是 clickabel
- c++ - C++ 向量排序给出 0 作为输出
- php - PHP PDO 代码的问题不会执行
- go - IIS 作为 golang socket.io 的反向代理
- php - 如果字符串中单词后的术语是浮点数
- android - 单击按钮时完全删除广告横幅
- javascript - 图像上方的三个.js 动画 - javascript