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();
我尝试过:
- 将预准备语句移动到两个单独的对象。
-
使用代码:
while($mysqli->more_results()){ $mysqli->next_result(); } //To make sure that no stray result data is left in buffer between the first //and second statements
- 使用 free_result() 和 mysqli_stmt->close()
PS:“不同步”错误来自第二个语句的“$stmt 1->错误”