MySQL 5.1.41, leading zero, is removed

I have a MySQL database where I want to store phone numbers by the way.

Field Type - INT (10)

When I try to insert a number starting with 0, for example 0504042858, it is stored as 504042858. This only happens with phone numbers with leading zeros. When a number starts with any other number, it is stored correctly.

What am I doing wrong?

+4
source share
3 answers

You should probably store the phone numbers as varchar . Phone numbers are only numeric.

You may also be interested in checking for the following stack overflow messages:

+5
source

You can specify the length of INT (11) with the value of the UNSIGNED_ZEROFILL attribute. it will fill in all 11 digits, and if any number of digits is less than 11, it will add a zero in front of the value. This may solve your problem.

+2
source

it removes the initial zero, because mathematically they are the same, and removing the initial zero is an optimization of fast storage. In addition, it also simplifies the reading of numbers by introducing a number supplemented by several leading zeros in a column of several hundred numbers.

I agree with Daniel to change your column to varchar.

+1
source

Source: https://habr.com/ru/post/1307991/


All Articles