调用未定义的方法mysqli_stmt :: free()

时间:2015-10-16 16:53:36

标签: php mysql mysqli

我想准备一个mysql脚本,首先根据给定的电子邮件检查用户的ID,然后在下一个查询中使用此找到的id。到目前为止我所做的如下:

$find_id  = "SELECT id from client 
         WHERE email = ? ";
$statement = $mysqli->prepare($find_id);
$statement->bind_param("s", $client_mail);
$statement->execute();
$statement->bind_result($id);
$statement->free();

$sql  = "SELECT client_name, contact_name from client_addr 
         WHERE client_id = ? AND is_actual < ? ";

$stmt = $mysqli->prepare($sql);
$stmt->bind_param("is", $id, "Y");
$stmt->execute();
$result = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
echo json_encode($result);

但现在我收到与此行有关的错误:

$statement->free();

Call to undefined method mysqli_stmt::free() in。 但是,当我删除此行时,我收到错误:

Uncaught exception 'mysqli_sql_exception' with message 'Commands out of sync; you can't run this command now' 

在这一行:

$stmt = $mysqli->prepare($sql);

我该如何解决?

1 个答案:

答案 0 :(得分:-1)

我相信您尝试使用的功能是mysqli_stmt::free_result()。您需要更改此行:

$statement->free();

要:

$statement->free_result();

第二个Uncaught exception发生是因为mysqli是一个无缓冲的 SQL查询处理程序,因此如果您使用{{{{{{{{{{{ {3}}然后您可以卸载mysqli缓冲区以声明新查询。