phpmysqlibindparam

What mysqli value for bind_param() i or s


I am using mysqli bind_param() when I'm inserting stuff to my DB.

When I tried to insert a phone number as "0737327373" the value got inserted as "737327373" without the leading "0". But when I changed bind_param("i", $phoneNumber) to bind_param("s", $phoneNumber) instead the value got inserted correctly as "0737327373". So should I use "s" instead of "i" when I'm inserting numbers with a leading 0 in it?

Also, I have a value that could be anywhere between (0-5) and (0-1) depending on what select/checkboxes a user check during a registration.

Should those values also be inserted as bind_param("s") since they could be "0" as well.


Solution

  • If you are inserting a "number" into a varchar field then yes, use an "s".

    In your case it makes no real sense to insert a phone number as an integer since you probably won't be doing any math analysis on it and you lose functionality (leading zeros, for example).