leading zeros dissapear from last inserted id right after save

I have an id field in a mysql db with zerofill, but when I try to access the new id right after the save() method, the id is returned with no leading zeros.

It is correctly inserted in the db (000003), but like I said, the last insert id returns it without the zeros  ??? so 000003 get displayed as 3, which messes up how I display my id’s in some cases

I would probably not have bothered with the zerofill in the DB, unless it's going to be critical for some kind of external parsing.

For display purposes you could use the str_pad function, like so:

My personal preference would be to put it inside a function in your model so you can just make a single call whenever it's required.


This is probably related with PDO. I also agree with SimonJ that controlling the display formatting using PHP is more appropriate and convenient.

Thanx guys for your input. I will follow your advice  :)