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