views:

145

answers:

2

Hello,

I have a MySQL database where i want to store phonenumbers among other things.

The fieldtype is INT(10)

When I try to insert a number starting with a 0, like 0504042858 it's stored like 504042858. This only happens with zeros when the number start with any other number it's stored correctly.

What am I doing wrong?

+2  A: 

You should probably store phone numbers as a varchar. Phone numbers are only numeric by accident.

You may also be interested in checking out the following Stack Overflow posts:

Daniel Vassallo
Hi, Thank you for your quick response. I was wondering if storing a number as a string isn't bad practice. Also why would MySQL delete my 0 without me asking it?
iggnition
It is not deleting it. 0504 is 504 in numeric terms... In addition, I would say that storing them as an `varchar` is in fact the good practice.
Daniel Vassallo
because integers doesn't have leading zeroes, 01, 0001 and 1 is still the same number , 1.
nos
Thank you everybody for your answers, I changed the fieldtype to varchar(10) yet still my zeroes are deleted.EDIT: emptied cache and suddenly works now, thanks everybody!
iggnition
A: 

it is removing the leading zero because mathematically they are the same and removing the leading zero is a quick storage optimization. In addition it also makes the numbers easier to read imagine a number padded with several leading zeros in a column of several hundred numbers.

I agree with Daniel change your column to a varchar.

Steve Robillard