Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL 5.1.41 leading zero is deleted

Tags:

mysql

I have a MySQL database where I want to store phone numbers 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 phone numbers with leading zeros. When the number start with any other number, it's stored correctly.

What am I doing wrong?

like image 202
iggnition Avatar asked Feb 27 '23 03:02

iggnition


1 Answers

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:

  • What datatype should be used for storing phone numbers in SQL Server 2005?
  • Common MySQL fields and their appropriate data types
like image 78
Daniel Vassallo Avatar answered Mar 07 '23 12:03

Daniel Vassallo