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
You are reaching the limit of the
INTdata type, 32 bits at 2147483647. You will need to change the column’s data type to either aVARCHAR()or a larger integer value such asBIGINT.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.