我正在使用 PHP 并在 MySQL 服务器上运行 SQL 查询。为了防止 SQL 注入,我正在使用 mysql_real_escape_string 函数。
对于数字转换,我也在以下方式中使用 (int):
$desired_age = 12;
$query = "select id from users where (age > ".(int)$desired_age.")";
$result = mysql_query($query);
但是,当变量包含更大的数字时,强制转换会失败,因为它们比int大。
但是,当变量包含较大的数字时,强制转换将失败,因为它们比int大。
(通俗易懂版)$user_id = 5633847511239487;
$query = "select age from users where (id = ".(int)$user_id.")";
$result = mysql_query($query);
// this will not produce the desired result,
// since the user_id is actually being cast to int
除了使用mysql_real_escape_string外,还有其他方法可以插入大量数字(如BIGINT),以防止SQL注入吗?