Clean 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

PHP intval value range: Related to the operating system, 32-bit system is-2147483648 to 2147483647, 64-bit system is-From 92233720368547758089223372036854775807.

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.

So the followingCodeIs incorrect:

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.

Related Article

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.