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