开发者

Do prepared statements cut a 0 off the front of a number in php?

开发者 https://www.devze.com 2023-03-02 18:56 出处:网络
I am inserting a number of fields into the database. One of the fields is a phone number field. If you start a number with \'01234\' for example, it will cut off the \'0\' at the beginning of the stri

I am inserting a number of fields into the database. One of the fields is a phone number field. If you start a number with '01234' for example, it will cut off the '0' at the beginning of the string.

I am using mysqli and prepared statements to insert the string into the DB, and I have a different insert query that is not using prepared statements where it does not cut off the '0' at the beginning, which leads me to assume the prepared statement is trimming the '0' off.

I also made the field it is inserting it into a varchar to see if that wou开发者_开发技巧ld make it work, but no luck.

Do you have any idea why it is cutting the '0' off at the beginning when I'm using the prepared statement? How can I get around this?


If at any point you are designating the phone number as an actual number (i.e. int, decimal, float, etc) it will remove any leading zeros.

For this reason, phone numbers should be accepted, transferred, and stored as strings. Since you never perform math on a phone number, it should present no problems.

I'm guessing that in your prepared statement or other step you are designating it as a number.


Make sure to use the correct $types in mysqli_stmt::bind_param.

0

精彩评论

暂无评论...
验证码 换一张
取 消