• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keeping the 0 in database input?

#1
[eluser]JasonS[/eluser]
When I put '07' into the database using code igniters database update function the number loses the 0. What do I need to do to keep the 0 on the number?

#2
[eluser]xwero[/eluser]
It is not because of CI. You can loose the 0 because the field in the database is an integer type field. There are two solutions for this. add an extra number, not zero of course Wink, in front of the value or change the field type to a text type.

#3
[eluser]AgentPhoenix[/eluser]
There is a "feature" in MySQL where, no matter if it's text or not, it'll truncate leading zeros. I ran in to that problem myself. MySQL recommends using zerofill, but what they don't tell you is that in some versions of MySQL, you can't set that attribute on integer fields. Fantastic, huh?

#4
[eluser]xwero[/eluser]
I never had any problems with truncating leading zeros in text type fields and my mysql versions go as low as 3.4. But it's good to know a zerofill attribute exists, i never looked into it because my hacks worked. It's not very professional but i like to do more than database coding :coolsmile:

#5
[eluser]AgentPhoenix[/eluser]
Bah, who needs professional work arounds? Hack away! Wink


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.