bind_param problem with binding boolean values(绑定布尔值的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 时遇到了一些问题.所以我在 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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:绑定布尔值的bind_param问题
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
