PHP Data Pre-storage cleanup note php intval and MySQL int value range different _php tutorial

Source: Internet
Author: User
PHP saves data to MySQL
It is intended to clean up the data before it is put into the DAO layer, such as varchar for trim,int intval.
One day it suddenly occurred to me that PHP intval the same value range as the MySQL int type?
Check it out, 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 of values: Operating system-related, 32-bit system is 2147483648 to 2147483647, 64-bit system is 9223372036854775808 to 9223372036854775807.
MySQL int value range: OS independent, 2147483648 to 2147483647, unsigned 0 to 4294967295.
MySQL bigint 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.

http://www.bkjia.com/PHPjc/322580.html www.bkjia.com true http://www.bkjia.com/PHPjc/322580.html techarticle PHP saves data to MySQL to clean up before data is stored in the DAO layer, such as varchar for trim,int intval. One day suddenly remembered that PHP intval range of values with the MySQL int class ...

  • 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.