Re: PHP/mySQL dropping zeros after inserting number into record
| From: | Daniel Brown | Date: | Sun, 17 Feb 2008 17:16:00 +0000 |
| Subject: | Re: PHP/mySQL dropping zeros after inserting number into record | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269434@lists.php.net to get a copy of this message | ||
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.
--
</Dan>
Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>