沃梦达 / 编程问答 / php问题 / 正文

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

本文标题为:绑定布尔值的bind_param问题

基础教程推荐