dtmbc1606 2015-10-16 16:53
浏览 41

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

I want to prepare a mysql script that first checks the id of the user based on given email and later on use this found id in the next query. What I did so far is as follows:

$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);

but now I'm getting the error related to this line:

$statement->free();

that says Call to undefined method mysqli_stmt::free() in. However, when I remove this line I'm getting the error:

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

on this line:

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

How can I fix it?

  • 写回答

1条回答 默认 最新

  • doucan4815 2015-10-16 17:10
    关注

    I believe the function you're trying to use would be mysqli_stmt::free_result().
    You'll need to change this line:

    $statement->free();
    

    To:

    $statement->free_result();
    

    The second Uncaught exception occurs because mysqli is an unbuffered SQL query handler, so you should store your results if you're looping simultaneous executions with something like $stmt->store_result(); and then you can unload the mysqli buffer to state a new query.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP