Php mysqli_stmt::bind_result():绑定变量的数量与中prepared语句中的字段数量不匹配
我使用的是一个准备好的语句,我在bind_param中传递的变量量与我预期的完全相同,但它仍然给我一个变量计数不匹配的错误Php mysqli_stmt::bind_result():绑定变量的数量与中prepared语句中的字段数量不匹配,php,mysqli,Php,Mysqli,我使用的是一个准备好的语句,我在bind_param中传递的变量量与我预期的完全相同,但它仍然给我一个变量计数不匹配的错误 $query = "select `shipping_name`,`shipping_address1`,`shipping_address12`,`shipping_city`,`shipping_state`,`shipping_postalcode`,`billing_name`,`billing_address2`,`billing_address22`,`bill
$query = "select `shipping_name`,`shipping_address1`,`shipping_address12`,`shipping_city`,`shipping_state`,`shipping_postalcode`,`billing_name`,`billing_address2`,`billing_address22`,`billing_city`,`billing_state`,`billing_postalcode` from puppy_shipping where unique_id=?";
$stmt = $db->prepare($query);
$bind = 'ssssssssssss';
if ($stmt) {
$stmt->bind_param('s', $id);
$stmt->execute();
$stmt->bind_result($bind, $shipping_name, $shipping_address1, $shipping_address12, $shipping_city, $shipping_state, $shipping_postalcode, $billing_name, $billing_address2, $billing_address22, $billing_city, $billing_state, $billing_postalcode);
while ($stmt->fetch()) {
}
$stmt->close();
}
你的问题是这条线
$stmt->bind_result($bind, $shipping_name,$shipping_address1,$shipping_address12, ....);
您试图绑定变量类型,就像使用bind_param一样,这是错误的-因为此函数没有这样的参数。bind_results only参数是您从查询中选择的值,而不是其他值
解决方案是从bind_结果调用中删除$bind,使其
$stmt->bind_result($shipping_name, $shipping_address1, $shipping_address12, ....);
参考文献
面向对象风格
$stmt->bind_result($name, $code);
程序风格
mysqli_stmt_bind_result($stmt, $name, $code);
bind_result没有像bind_param那样的类型绑定,所以请删除$bind变量.done!现在我犯了这个错误!无法在中通过引用传递参数1,现在看起来是这样的$stmt->bind_result'ssss'、$shipping_name、$shipping_address1、$shipping_address12、$shipping_city、$shipping_state、$shipping_postalcode、$billing_name、$billing_address2、$billing_address22、$billing_city、$billing_state、$billing_postalcode;正如我所说,bind_result不需要绑定类型-所有参数都是您选择的值,仅此而已。看看手册lol,我的坏了,它完成了,谢谢它对我来说是新的,所以我犯了一个错误