Re: PHP/mySQL dropping zeros after inserting number into record

From: Date: Sun, 17 Feb 2008 18:43:02 +0000
Subject: Re: PHP/mySQL dropping zeros after inserting number into record
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-269442@lists.php.net to get a copy of this message
Daniel Brown wrote:
On Feb 16, 2008 6:22 PM, Rob Gould <gouldimg@mac.com> wrote:
I've got a PHP script that inserts "00012345678" into a record in a mySQL database (it's a barcode). Things work ok unless the number has preceding zeros, and then the zeros get cut off and all I get is "12345678". I have the mySQL database fieldtype set to bigint(14). If the maximum length a barcode can be is 14, is there a better fieldtype to use that will keep the zeros? (or some way for PHP to tell mySQL not to chop off the zeros?)
    Rob,
    A few years ago, I developed a full-on inventory management system
(with barcode printing and assignment, as well as scanning) and found that with Code 39 I didn't have the issue, but when using UPC or some other format, I often had to convert the code to string(). Then insert the data into a CHAR or VARCHAR column, because to most systems, INT 001234 is equal to INT 1234, but with more overhead, which is then normally trimmed.
zerofill is the way - the stupid but works way is to store the barcodes backwards :D or indeed base convert them from 10 to 32..

« previous php.general (#269442) next »