bind_param()i或s的mysqli值是多少 [英] What mysqli value for bind_param() i or s

查看:69
本文介绍了bind_param()i或s的mysqli值是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向数据库中插入内容时,我正在使用mysqli bind_param().

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

当我尝试将电话号码插入为"0737327373"时,该值将插入为"737327373",且前导"0"无效.但是,当我将bind_param("i", $phoneNumber)更改为bind_param("s", $phoneNumber)时,该值正确插入为"0737327373".因此,当我插入前导0的数字时,应该使用"s"而不是"i"吗?

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?

此外,我的值可以介于(0-5)和(0-1)之间,具体取决于用户在注册过程中选中的选择/复选框.

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.

这些值也应作为bind_param("s")插入,因为它们也可能为"0".

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

推荐答案

如果要在varchar字段中插入数字",则可以,请使用"s".

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).

这篇关于bind_param()i或s的mysqli值是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆