相关疑难解决方法(0)

PHP命令不同步错误

我在PHP/MySQLi中使用两个预准备语句从mysql数据库中检索数据.但是,当我运行语句时,我得到"命令不同步,你现在无法运行命令"错误.

这是我的代码:

    $stmt = $mysqli->prepare("SELECT id, username, password, firstname, lastname, salt FROM members WHERE email = ? LIMIT 1";
    $stmt->bind_param('s', $loweredEmail);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($user_id, $username, $db_password, $firstname, $lastname, $salt);
    $stmt->fetch();

    $stmt->free_result();
    $stmt->close();

    while($mysqli->more_results()){
        $mysqli->next_result();
    }

    $stmt1 = $mysqli->prepare("SELECT privileges FROM delegations WHERE id = ? LIMIT 1");
    //This is where the error is generated
    $stmt1->bind_param('s', $user_id);
    $stmt1->execute();
    $stmt1->store_result();
    $stmt1->bind_result($privileges);
    $stmt1->fetch();
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

  • 将准备好的语句移动到两个单独的对象.
  • 使用代码:

    while($mysqli->more_results()){
        $mysqli->next_result();
    }
    //To make sure that no stray result data is left in buffer between the …
    Run Code Online (Sandbox Code Playgroud)

php mysql mysqli

26
推荐指数
3
解决办法
2万
查看次数

标签 统计

mysql ×1

mysqli ×1

php ×1