Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MySQLi问题,已准备好的SELECT变量未绑定_Php_Mysqli_Prepared Statement - Fatal编程技术网

PHP MySQLi问题,已准备好的SELECT变量未绑定

PHP MySQLi问题,已准备好的SELECT变量未绑定,php,mysqli,prepared-statement,Php,Mysqli,Prepared Statement,还有一个PHP问题可能很简单,但我真的非常感谢任何帮助 我的函数进行mysqli计数,但它绑定到的$count参数没有更改,即使sql运行良好并且没有错误 职能: function itemsCount ($conn, $list_id) { $count = 0; if (!($stmt = $conn->prepare("SELECT count(uid) FROM collection.user_list_item WHERE list_id = ?"))) {

还有一个PHP问题可能很简单,但我真的非常感谢任何帮助

我的函数进行mysqli计数,但它绑定到的$count参数没有更改,即使sql运行良好并且没有错误

职能:

function itemsCount ($conn, $list_id) {
    $count = 0;
    if (!($stmt = $conn->prepare("SELECT count(uid) FROM collection.user_list_item WHERE list_id = ?"))) {
      echo "Prepare failed: " . $mysqli->error;
   }
   if (!($stmt->bind_param('i', $list_id))) {
      echo "Bind failed: " . $stmt->error;
   }
   if (!($stmt->execute())) {
      echo "Execute failed: " . $stmt->error;
   }
   if (!($stmt->bind_result($count))) {
      echo "Bind failed: " . $stmt->error;
   }
   echo $count;
   $stmt->close();
   return $count;
}
电话:

public function doAdd ($conn, $list_id, $item_id) {
   if ($this->itemsCount($conn, $list_id) < 20) {
      ...do stuff ...
   }
}
公共函数doAdd($conn、$list\u id、$item\u id){
如果($this->itemscont($conn,$list\u id)<20){
…做事。。。
}
}

对不起,代码不是很好,但是请帮我指出正确的方向

var_dump$list_id,参数bind i,需要一个整数。我希望您的var是一个字符串,您可以通过var_转储看到它。将字符串强制转换为int,或者使用不同的参数绑定。

$stmt->bind_result()
之后仍然需要调用
$stmt->fetch()
才能实际检索行。谢谢@MichaelBerkowski!我现在觉得自己很愚蠢…PHP会在必要时自动将字符串转换为整数。
I
参数to
bind_param
告诉它这是必要的。