绑定布尔值的bind_param问题

bind_param problem with binding boolean values(绑定布尔值的bind_param问题)
本文介绍了绑定布尔值的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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)