【发布时间】:2021-02-20 10:48:53
【问题描述】:
我想执行两个查询,我得到“命令不同步;你现在不能运行这个命令” 我已经查看了针对同一问题的先前问题,但无法找出解决方案。我知道这是因为我正在运行两个查询。
谁能告诉我我做错了什么?
查询一:
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>";
【问题讨论】:
-
我认为您的问题得到解答的地方是stackoverflow.com/questions/27899598/… 和php.net/manual/en/mysqli.multi-query.php#102837。在运行下一个查询之前,您需要对第一个多重查询的结果进行处理。
-
我认为你是对的@Chris Lear,但我根本不知道该怎么做:-(
-
永远不要使用
multi_query()!!!
标签: php mysqli mysqli-multi-query