绑定布尔值的 bind_param 问题 [英] bind_param problem with binding boolean values

查看:29
本文介绍了绑定布尔值的 bind_param 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PHP5 中使用 mysqli_stmt::bind_param 绑定布尔值时遇到问题.

I have a problem binding booleans using mysqli_stmt::bind_param in PHP5.

SQL 查询如下:

insert into `nvp_notes` (subject,messageid,receivedate,read) values (?,?,?,?)

其中 'read' 是一个 tinyint,可以是 0 或 1,因为我在使用 mysqli 时遇到了 bit 问题.所以我在 bind_param 中列出的类型是:

Where 'read' is a tinyint, either 0 or 1, as I've had issues with bit using mysqli. So the types that I list in bind_param are:

$stmt->bind_param('sdsd', ...);

我也试过 'sdsb' 和 'sdss' 但似乎没有任何效果,我总是收到消息:

I've also tried 'sdsb' and 'sdss' but nothing seems to work, and I always get the message:

警告:mysqli_stmt::bind_param(): 变量数与准备语句中的参数数不匹配

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

当我删除语句中的读取字段时,一切正常.我已经用完了这个想法.bind_param 肯定适用于布尔值吗?

When I remove the read field in the statement everything works fine. I've run out of ideas with this one. Surely bind_param works with booleans?

推荐答案

您可以使用 intval 将布尔值转换为 1 或 0()(或者用 (int)(integer) 来转换).根据 mysqli_stmt::bind_param() 的文档,您可以绑定的唯一类型是整数、双精度数、字符串和 blob.

You could convert the boolean to a 1 or 0 using intval() (or cast it with (int) or (integer)). According to mysqli_stmt::bind_param()'s documentation, the only types you may bind are ints, doubles, strings, and blobs.

这篇关于绑定布尔值的 bind_param 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆