Php integer overflow problems

Source: Internet
Author: User
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, it is easier to use intval before false, such as if (intval ('000000 '))... then proceed & nbsp; to find the ec 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.