Sol Bethany Reaves
Sol Bethany Reaves

Reputation: 387

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

Upvotes: 4

Views: 5157

Answers (2)

Amirkhm
Amirkhm

Reputation: 1096

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

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157872

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

Upvotes: 4

Related Questions