Вопрос

I'm interacting with the facebook api which is sending me back some rather large id for instance

$facebook_action['id'] => "123540931515315"
intval($facebook_action['id']) gives me "2147483647"

In my database I had planned to store it as an integer however these might be too big as in php conversion returns to me the largest int value. Should I just be storing these as a string instead or how do I handle this?

In MySQL I see I can use BIG INTEGER however how can I handle this in PHP?

Это было полезно?

Решение

You're exceeding the limit on integer types in PHP. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. Because the value that you are working with exceeds 2147483647, it is storing 2147483647. See http://php.net/manual/en/function.intval.php. You may want to do what some of the commenters suggest, and use varchar instead, especially if these values could potentially contain non-numeric characters.

Другие советы

Upgrade your system to 64 bit architecture to handle that large integer value :)

The reason for you getting 2147483647 is clearly stated in the "Return Values" section of intval.

i.e. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top