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.