Pre-storage of PHP Data notice PHP intval is different from MySQL's int value range

Source: Internet
Author: User
Tags empty insert mysql range return trim
PHP saves data to MySQL
Plan to clean the data before the DAO layer, such as varchar for trim,int intval.
One day it suddenly occurred to me that the PHP intval range is the same as the MySQL int type?
Checked, not the same ...
http://php.net/manual/en/function.intval.php
Http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-types
PHP intval Range: Operating system-related, 32-bit system on 2147483648 to 2147483647, 64-bit system for-9223372036854775808 to 9223372036854775807.
MySQL int value range: OS independent, 2147483648 to 2147483647, unsigned 0 to 4294967295.
MySQL bigint value range: OS independent, 9223372036854775808 to 9223372036854775807, unsigned 0 to 18446744073709551615.
so the following code is wrong:
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 into". $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: Still thinking, ready to use regular expressions.

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.