【问题标题】:I get: Commands out of sync; you can't run this command now? [duplicate]我得到:命令不同步;你现在不能运行这个命令? [复制]
【发布时间】: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>";

【问题讨论】:

标签: php mysqli mysqli-multi-query


【解决方案1】:

如果我正确理解了另一个答案,这就是该怎么做:

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();
    }

    //...

【讨论】:

    猜你喜欢
    • 2016-05-28
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 2013-04-08
    • 2016-04-11
    • 2021-10-13
    相关资源
    最近更新 更多