How to use mysqli_stmt_bind_param for integers, boolean, etc

I am trying to use this method to bind the parameters to their specific types:

mysqli_stmt_bind_param(mysqli_stmt stmt, string types, mixed &var1 [, mixed &...])

I understand that the second parameter is a string of types where

* s is for strings * d is for decimals * i is for integers * b is for blob 

I'm not sure what "blob" is.

Now my question is, how could I bind boolean-type variables into this method? Is there such a way to do that?

More information below. These are my variables: (roomType, roomPrice, roomQty, numBeds, smokingAvail, accessibleRm)

 roomType: string coming from web form  roomPrice: decimal coming from a web form  roomQty: integer coming from web form  numBeds: integer coming from web form  smokingAvail: Boolean coming from web form  accessibleRm: Boolean coming from web form 
1

2 Answers

You can use string for all the types. Mysql will sort them out.

To pass boolean you should use i as well: if you pass string it always consider it as something which is not equal to false (in the case of boolean unless you pass empty string)

$stmt = $mysqli->prepare ('some query'); $stmt->bind_param("dsi",$price,$name,$sex); 

and to pass integer i and for decimal d

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like