0

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?

5
  • 2
    I ran into the same issue. I just made it a varchar. Not saying it's best practice, but it's what I did. Also because what if Facebook decides to add letters to their IDs or something strange. Since you don't control the data coming in, I say make it flexible. Integers are pretty rigid and they can't start with 0. So, just saying, strings are more flexible with data you don't control. Commented Aug 11, 2013 at 2:47
  • varchar is the way to go and treat it as a string in PHP Commented Aug 11, 2013 at 2:50
  • Strings... You don't have any other choice anyways... Commented Aug 11, 2013 at 2:50
  • ah ok thanks! I actually just got it working with BIG INT in mysql, treating it as string in php and let mysql do the conversion to big int although it didn't feel robust. Commented Aug 11, 2013 at 2:50
  • I'd keep it as a string. It's not like you're going to be making calculations with that number anyway, or that it's representing a quantity or anything like that. It is in fact intended as a string, only that it contains numbers. Commented Aug 11, 2013 at 2:50

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.