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
The value range of php intval is related to the operating system. For 32-bit systems, values range from-2147483648 to 2147483647. for 64-bit systems, values range from-9223372036854775808 to 9223372036854775807.
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.
The following code is incorrect:
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 '". $ 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.