Php integer overflow problem today I am writing a program and found that the inserted MYSQL data is inconsistent with the POST debugging and found that it is an error during data conversion. for example, if I want to convert a mobile phone number to an int, the mobile phone number is any character. if it is not a mobile phone number, if it is false, intval is used before, for example, if (intval (13688017729 ))... then proceed & nbsp; to find the echointval (13688017729 php integer overflow problem
Today, I wrote a program and found that the inserted MYSQL data is inconsistent with the POST data. debugging found that it was an error during data conversion.
For example, if I want to convert a mobile phone number to an int, if the phone number is any character and not a mobile phone number, intval is used before false.
For example
If (intval ('000000 '))
... And then proceed
Found
Echo intval ('000000'); this sentence is not equal to 13688017729
My PDO is doing this. let me see how to fix this BUG.
If (array_key_exists ($ key, $ data )){
If (isset ($ data [$ key]) {
If ($ table_column [$ key] ["d_type"] = "decimal" | $ table_column [$ key] ["d_type"] = "double "){
$ Newdata [$ key] = doubleval ($ data [$ key]);
} Elseif ($ table_column [$ key] ["d_type"] = "int" | $ table_column [$ key] ["d_type"] = "smallint" | $ table_column [$ key] ["d_type"] = "tinyint" | $ table_column [$ key] ["d_type"] = "mediumint" | $ table_column [$ key] ["d_type"] = "bigint ") {
$ Newdata [$ key] = intval ($ data [$ key]);
} Elseif ($ table_column [$ key] ["d_type"] = "float "){
$ Newdata [$ key] = floatval ($ data [$ key]);
} Else {
$ Newdata [$ key] = $ data [$ key];
}
}
}
------ Solution --------------------
You cannot do this! The mobile phone number is out of the integer range.
Check whether all the numbers are composed of is_numeric functions or regular expressions.
------ Solution --------------------
The error occurs because the database length overflows, not because of your type conversion. if you want to store the mobile phone number, you can change the field type to bigint.