Clear php Data before warehouse receiving. Note that the int value range of php intval is different from that of mysql.

Source: Internet
Author: User

Php saves data to mysql
We plan to clean up data before warehouse receiving at the dao layer, such as varchar trim and int for intval.
One day, I suddenly remembered that the value range of php intval is the same as that of mysql's int type?
I checked it. It's different ......
Http://php.net/manual/en/function.intval.php
Http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-types
The value range of php intval is related to the operating system. For 32-bit systems, values range from-2147483648 to 2147483647. for 64-bit systems, values range from-9223372036854775808 to 9223372036854775807.
Mysql int value range:-2147483648 to 2147483647, and 0 to 4294967295.
Mysql bigint value range:-9223372036854775808 to 9223372036854775807, which is not related to the operating system. The value range is 0 to 18446744073709551615.
The following code is incorrect:
Copy codeThe Code is as follows:
Public function insert ($ data)
{
If (isset ($ data ['content']) &! Empty ($ data ['content'])
{
$ Data_for_query ['content'] = trim ($ data ['content']);
}
Else
{
Return false;
}
If (isset ($ data ['user _ id']) &! Empty ($ data ['user _ id'])
{
$ Data_for_query ['user _ id'] = intval ($ data ['user _ id']);
}
Else
{
Return false;
}
$ SQL = "INSERT '". $ this-> table_name. "'(". $ this-> db-> implodeToColumn (array_keys ($ data_for_query )). ") VALUES (". $ this-> db-> implodeToValues (array_values ($ data_for_query )). ")";
$ This-> db-> query ($ SQL );
$ Id = $ this-> db-> lastInsertId ();
If (empty ($ id ))
{
Return false;
}
Else
{
Return $ id;
}
}

Solution: You still want to use a regular expression.

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.