問題描述
我在 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 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!