The value inserted in mysql is different from the value in the query string

I use facebook api to get facebook user id and then paste it into mysql. It works great for the most part. But for some strange reason, the value that is inserted into the fb_id column in my db is different from the value that is supposed to be inserted into 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 is inserted into the database is "2147483647". The correct value should be "100000034641562". It is strange that in the column under the name "photo" the value equal to ". $ Fb_id." Should be indicated. Jpg ". Basically, the facebook id is just with" .jpg "at the end. This column has the correct value inserted into it (100000034641562.jpg). But there is no fb_id column. I thought I might have to adjust the sorting for the length column, but that is not a problem.

Any ideas?

Thanks,

A spear

+4
source share
1 answer

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

 ALTER TABLE users MODIFY fb_id BIGINT; 

Check the MySQL documentation for integer data types for relevant restrictions.

And for some humorous context, read this article in The Daily WTF.

+7
source

All Articles