gpt4 book ai didi

php - 在 boolean 、mysqli_stmt::store_result 和 mysqli_stmt::close() 上调用成员函数 bind_param()

转载 作者:行者123 更新时间:2023-12-03 19:25:24 24 4
gpt4 key购买 nike

这是我的代码...它是关于使用 php mysqli 扩展

<?php
error_reporting(E_ALL);
$db = new mysqli("localhost","root","","dee");

if ($db->connect_errno)
{
die('Unable to connect to database');
}
mysqli_set_charset($db,"utf8");


$storeid=4;
$categoryid=6;

$statement_store = $db->prepare('SELECT * FROM tbl_store WHERE store_id=?');
$statement_store->bind_param('i',$storeid);
$statement_store->execute();

$statement_store->store_result();//---------------(1)

$statement_store->bind_result($store_id,$store_name,$store_description,$store_image,$store_open,$store_close,$store_foldername);
$statement_store->fetch();
$store = $store_name;

//$statement_store->close();//--------------(2)


$statement_category = $db->prepare('SELECT * FROM tbl_category WHERE category_id=?');
$statement_category->bind_param('i',$categoryid);
$statement_category->execute();
$statement_category->bind_result($category_id,$category_name);
$statement_category->fetch();
$category = $category_name;

echo $store;
echo '<br>';
echo $category;

?>
  • fatal error :在 bool 错误时调用成员函数 bind_param() 给出
    不使用 (1) 和 (2) 时
  • 当使用 (1) 或 (2) 时没有给出错误
  • 当同时使用 (1) 和 (2) 时不会给出错误

  • 谁能告诉我这里发生了什么?

    最佳答案

    不使用时 store_result()close()那么你的第一个准备好的语句(或它的结果)仍然是“事件的”。这意味着您必须以某种方式读取数据,然后才能发出新的准备好的语句。因此,您的第二个 prepare()语句将失败,它返回 bool 值 false .

    检查 $db->error字段,您将看到“命令不同步;您现在无法运行此命令”错误消息。来自 MySQL 手册 B.5.2.14 Commands out of sync :

    If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order.

    This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.

    关于php - 在 boolean 、mysqli_stmt::store_result 和 mysqli_stmt::close() 上调用成员函数 bind_param(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33286111/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com