I got some mysterious bug ..
Okay so I’m working in LocalHost with The latest version on MySQL. I’m working with CodeIgniter (2.0.2)
I’m trying to implement a function like that in a model :
function saveMyFriends($friends_list){
$this->load->library('encrypt');
foreach($friends_list as $friend){
// echo $friend['id'].' : '.utf8_decode($friend['name']).'</br>';
$query_str ="INSERT INTO sc_friends (fb_id, fb_friends_id, fb_friends_name) VALUES ( ?, ?, ?)";
$fb_id =$this->session->userdata('user_fbid');
$this->db->query($query_str, array($fb_id, $friend['id'], sha1(utf8_decode($friend['name']))));
}
return TRUE;
}
Which is supposed to save in a database my list of Facebook friends but it happens that around 5% of the results have the same Fb_id … Which is impossible. So I’ve tried to enter some friends manually, I just changedenter code here few lines :
function saveMyTwoFriends(){
$this->load->library('encrypt');
$query_str ="INSERT INTO sc_friends (fb_id, fb_friends_id, fb_friends_name) VALUES ( ?, ?, ?)";
$this->db->query($query_str, array(7518777XX, 1000028691344XX, sha1(utf8_decode('XXX XXXX'))));
return TRUE;
}
(Of course, X is either a real number or a Real Name)
But once again , in my database, when I entered the third one manually (the one I give you here in example) I had the recurring “same id” : “2147483647”
How is that possible ?
Thanks 🙂
2147483647 is the biggest integer representable in 32-bit PHP. If your database library tries to treat bigger number like 100002869134477 as integer – what you get is 2147483647. You may use floats or constant strings or extensions like bcmath or gmp is you need to work with larger numbers.