简体   繁体   English

MySQL截断我的第一个零数据

[英]MySQL truncates my first zeros data

I have a MySQL column "phone" , and when data comes from my php form, if there's a zero at the beginning, it will disappear in the table, for example : " 06719823 " becomes " 6719823 " 我有一个MySQL列“ phone”,当数据来自我的php表单时,如果开头为零,则它将在表中消失,例如:“ 06719823 ”变为“ 6719823

I first though it was a problem from php, cause I'm using mysql_real_escape_string(), but then I tried to modify the SQL field directly on phpmyadmin, and I can't add a first 0, it always delete it. 我首先尽管这是php的问题,但由于我使用的是mysql_real_escape_string(),但后来我尝试直接在phpmyadmin上修改SQL字段,但我无法添加前0,它总是将其删除。

Colonne     Type     Interclassement    Attributs   Null    Défaut  Extra
phone       int(10)                                 Oui     NULL    

What's wrong ? 怎么了 ? Should I assign an "interclassement" utf8_general_ci ? 我应该分配一个“互类” utf8_general_ci吗?

将10位电话号码的列类型更改为char(10)

If the column type is int (integer), the number will be internally represented as an integer , meaning "first 0s" won't be stored, as they hold no meaning for integers. 如果列的类型为int(整数),则该数字将在内部表示为整数 ,这意味着将不存储“前0个”,因为它们对整数没有任何意义。

Since what you are actually trying to store has meaning as a sequence of characters , and not as a quantity, it would make more sense to store it as a char(n) , for n-digit sequences, or as a varchar for sequences whose size varies a lot. 由于您实际尝试存储的内容的含义是字符序列而不是数量,因此将其存储为char(n) ,n位序列或varchar序列会更有意义。大小差异很大。

Make your phone attribute as Varchar or Text to avoid this. 将您的电话属性设置为Varchar或Text可以避免这种情况。

Phone numbers can at time also contain brackets and hyphens plus you can avoid your problem as well. 电话号码有时也可以包含方括号和连字符,而且您也可以避免出现问题。

Change your data type. 更改您的数据类型。 Int Data type will not store the starting 0's. Int数据类型将不存储开头的0。

You can try as suggested above char or varchar 您可以按照上面的建议尝试使用char或varchar

Integers : 06719823 = 6719823 = 0006719823

如果您想在开头保留零,请将手机另存为varchar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM