【问题标题】:Call to a member function bind_param() on boolean ,mysqli_stmt::store_result and mysqli_stmt::close()在布尔值、mysqli_stmt::store_result 和 mysqli_stmt::close() 上调用成员函数 bind_param()
【发布时间】:2015-10-22 16:36:41
【问题描述】:

这是我的代码...它是关于使用 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;

?>
  1. 致命错误:在布尔错误上调用成员函数 bind_param() 给出 当不使用 (1) 和 (2) 时
  2. 当使用 (1) 或 (2) 时不给出错误
  3. 同时使用 (1) 和 (2) 时不会出错

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

【问题讨论】:

    标签: php mysqli prepared-statement


    【解决方案1】:

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

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

    如果您的客户端代码中出现Commands out of sync; you can't run this command now,则说明您调用客户端函数的顺序错误。

    例如,如果您使用mysql_use_result() 并在调用mysql_free_result() 之前尝试执行新查询,则可能会发生这种情况。如果您尝试执行两个返回数据的查询而不在两者之间调用mysql_use_result()mysql_store_result(),也会发生这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      相关资源
      最近更新 更多