PHP5 sqli bind_param bind to boolean problem

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

The SQL query looks like this: insert into nvp_notes (subject, messageid, receivedate, read) values ​​(?,?,?,?)

Where 'read' is tinyint, either 0 or 1, since I had bit problems using mysqli. Thus, the types that I list in bind_param are as follows:

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

I also tried 'sdsb' and 'sdss' but nothing works and I always get the message:

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

When I delete the read field in the instruction, everything works fine. I have run out of ideas with this. Of course bind_param works with booleans ??

+6
php mysqli boolean prepared-statement
source share
3 answers

You can convert a boolean value to 1 or 0 using intval () (or pass it using (int) or (integer)). According to the mysqli_stmt :: bind_param () documentation , the only types you can bind are ints, doubles, strings and blobs.

+10
source share

Thanks for the answer, I finally managed to fix this problem (after you tried type casting and even left it from bind_param, setting it to 1 or 0 in the request). In any case, β€œreading” is the reserved column name in MySQL, so I just changed the column name and it works fine. It seems strange to get this error message, however for this problem.

+1
source share

Like what you need to bind to is Integer, I would swtich "d" (double) with "i":

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

0
source share

All Articles