4

I'm using the facebook api to fetch the user's facebook id and then insert it into mysql. It's working fine for the most part. But, for some bizarre reason, the value that gets inserted into the fb_id column in my db is different from the value that is supposed to be inserted in the query string. My code is as follows:

$facebook = new Facebook(array(
'appId' => '12345',
'secret' => '12345',
'cookie' => true
));

$access_token = $facebook->getAccessToken();

if($access_token != "") 
{
$user = $facebook->getUser();

if($user != 0)
{
        $user_profile = $facebook->api('/me');   

        $fb_id = $user_profile['id'];
        $fb_first_name = $user_profile['first_name'];
        $fb_last_name   $user_profile['last_name'];
        $fb_email = $user_profile['email'];


    $img_data = file_get_contents('https://graph.facebook.com/'.$fb_id.'/picture?type=large');
    $save_path = 'img/profile_pics/large/';

        file_put_contents(''.$save_path.''.$fb_id.'.jpg', $img_data);

    $insert =   "INSERT INTO users 
            (first_name, last_name, email, photo, fb_id, accuracy_rate, date_joined, date_joined_int) 
                 VALUES 
            ('".$fb_first_name."', '".$fb_last_name."', '".$fb_email."', '".$fb_id.".jpg', '".$fb_id."', '100', '".date("F j, Y")."', '".idate("z")."')";
    $result = mysql_query($insert)or die(mysql_error());
}
}

The value that gets inserted into the DB is "2147483647". The correct value should be "100000034641562". What is strange is that the column titled "photo" is supposed to be populated with a value that is equal to "".$fb_id.".jpg". Basically, the facebook id just with a ".jpg" at the end. That column has the correct value inserted into it (100000034641562.jpg). But, the fb_id column isn't. I thought that maybe I had to adjust the collation for length of the column, but that wasn't the problem.

Any ideas?

Thanks,

Lance

1
  • int(40)... way more than enough characters that will ever be inserted into that column. But, just to be on the safe side Commented Aug 18, 2012 at 14:57

1 Answer 1

7

You are reaching the limit of the INT data type, 32 bits at 2147483647. You will need to change the column's data type to either a VARCHAR() or a larger integer value such as BIGINT.

ALTER TABLE users MODIFY fb_id BIGINT;

Look over MySQL's documentation on integer data types for the associated limits.

And for some humorous context, read this story over at The Daily WTF.

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

2 Comments

Awesome! Changed it to a bigint type and it works just fine! Thanks a bunch!

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.