NYCPHP Meetup

NYPHP.org

[nycphp-talk] TRUNCATING MySQL FIELDS

PaulCheung paulcheung at tiscali.co.uk
Sun Jul 29 04:36:02 EDT 2007


Hi Mike,

Thank you for pointing me in the right direction. My problem was 
mis-understanding what INT(8) meant.

Paul

----- Original Message ----- 
From: "Michael Sims" <jellicle at gmail.com>;
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Saturday, July 28, 2007 7:36 PM
Subject: Re: [nycphp-talk] TRUNCATING MySQL FIELDS


> On July 28, 2007, PaulCheung wrote:
>
>> When I set the table up I set the LICENCE to INT(8). When populating this
>> field I was expecting any number larger than 8 digits to be truncated and
>> any number less than 8 digits to be padded out with zeros, in both cases
>> this is not happening.
>
> Nope.  An Int is an Int is an Int.  The number in parentheses specifies 
> how
> large the zerofill will be, but, oddly, you have to specify the zerofill
> separately.
>
> So if you declare a column as "int(5) zerofill", it means that it's an int
> (four bytes of storage, range 2^31 to -2^31), and if you output it and 
> it's
> less than 5 decimal digits, it will be padded with zeroes up to five
> characters.
>
> It's bad practice to intentionally try to truncate data when inserting it
> into a table.  I might come along later and fix your "bug" without
> understanding what you were trying to do.  Probably you should tell your
> random number generator to give you a number of exactly eight digits, if
> that's what you want.
>
> Michael Sims
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 



More information about the talk mailing list