应该是一个简单的问题,我只是不熟悉 PHP 语法,我想知道以下代码是否可以免受 SQL 注入攻击?:
private function _getAllIngredients($animal = null, $type = null) {
$ingredients = null;
if($animal != null && $type != null) {
$query = 'SELECT id, name, brief_description, description,
food_type, ingredient_type, image, price,
created_on, updated_on
FROM ingredient
WHERE food_type = \'' . $animal . '\'
AND ingredient_type =\'' . $type . '\';';
$rows = $this->query($query);
if(count($rows) > 0) {
等等等等等等
我搜索了一下,似乎注射安全代码看起来与 WHERE food_type = \'' 不同。$动物。'\' 在这里使用的语法。
抱歉,我不知道这里使用的是什么版本的 PHP 或 MySQL,或者是否正在使用任何 3rd 方库,任何有专业知识的人都可以提供任何意见吗?
更新
\ 在语句中的作用是什么?:
WHERE food_type = \'' . $animal . '\'
在我的谷歌搜索中,我遇到了很多关于mysql_real_escape_string
......这是防止 SQL 注入和其他讨厌的功能的功能吗?
类声明是:
class DCIngredient extends SSDataController
那么可以想象mysql_real_escape_string
包含在里面吗?
我应该要求查看 SDataController 的实现吗?