I have some phone numbers (validated such that all containing only integers, no - or + in them) as strings in a text file.
I am doing a simple mysql update on a mysql table which has phone number column as int(12). Note that I convert each phone number extracted from the text file to integer using intval().
The problem that I am facing is that instead of the numbers being inserted I just get 2147483647 to be inserted in each column. I guess I am making a small silly mistake somewhere, but still I can’t figure it out. Can anyone explain what mistake am I making?
EDIT: Here is my the piece of code I am using (It does not give any sql error):
$sql="UPDATE ".$table." SET mobile = ".intval($smob).", phone = ".intval($sphone)." WHERE roll='".$sroll."'";
mysql_query($sql, $con) or die(mysql_error());
Excerpt from
intval()manual:What you are getting is a maximum number for signed integer on a 32bit machine.
I would strongly advise you to not use this function for phone number conversions. One of the simple reasons is that my mobile number is 11 digit number (without leading + or double zero for international access), and I believe there are some countries that have even more digits.
Why you would need to store phone numbers as
int‘s? Since most likely you are not doing some calculations and statistics on who might have a biggest phone number among your clients, and this data is probably used only for invoicing or a contact info, you could just leave that as a string.