Re: Trying to insert a large number from php to mysql
| From: | Robert Cummings | Date: | Wed, 20 Dec 2006 16:14:43 +0000 |
| Subject: | Re: Trying to insert a large number from php to mysql | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-246085@lists.php.net to get a copy of this message | ||
On Wed, 2006-12-20 at 10:58 -0500, Jon Anderson wrote:
> WeberSites LTD wrote:
> > I'm trying to insert the number 1970324970930197 into a mysql BigInt(20)
> > field.
> > If I do a direct insert from mysql command prompt and select the record I
> > get
> > back the same number.
> >
> > If I do this from PHP I get back 1970324970930000. Notice that the 197 at
> > the
> > end is not 000.
> AFAIK, PHP uses 32-bit (signed) integers, so you're stuck to values no
> bigger than around 2 billion. Anything larger, and you have to store it
> as a string: use a "BigInt" class, or GMP functions to do calculations.
> I believe MySQL will do the right thing if you insert a string "integer"
> into an integer field.
Just to add... the reason the number changes is because PHP detects that
it is too big and so stuffs it into a float where precision is then
lost.
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'