MySQL int removes 0
source link: https://www.codesd.com/item/mysql-int-removes-0.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
MySQL int removes 0
Hi I have got a column in my database which is set to Int.
But my data always starts with a 0 so whenever I add a new record, it strips the 0 off and I don't want it to do that incase the first character has to be a 1 at some point.
How can I overcome this issue?
Is the best way to use VARCHAR any then validate using PHP?
Update
If I enter 02118272 it is saved to the database as 2118272.
I think that you should use varchar type for that field. If you want to convert a variable to integer in php you can simply do this:
$var=preg_replace("/[^\d]/","",$var);
with this you delete all characters that aren't numbers and then you can put this value into the db preserving the initial 0.
Related Articles
MYSQL INT addition
Can the MySQL INT type be null
Primary key in MySQL: INT (n) or UUID as a varchar (36)
Use PHP or MySQL to remove duplicates on large lists?
Mysql int will not store zero based on null.
Get permutations of an int [] remove sets of duplicates
MySQL INT 5-byte type?
What is the actual scope of a MySQL INT column in this situation?
Mysql int (11) number out of range
Is it better to use 0 or NULL as the default for MySQL INT fields that store dates?
MySQL - Int Int (9.455.487) takes more space than string (John) in mySQL?
Codeigniter Complex MySQL Query - Removing Backticks - is this a security issue?
The MySQL subquery removes the entire line when it does not match a result
MySQL - Effectively removes all records except the last N
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK