我的原始 SELECT 查询有效,但不适用于 PHP 代码中插入的变量。
这是我的实际选择查询:
SELECT * FROM `program_list`
WHERE
speciality LIKE '%IM%'
AND (stepone2digit <= 78 OR stepone2digit=0)
AND (stepone3digit <= 189 OR stepone3digit=0)
AND (steptwock2digit <= 78 OR steptwock2digit=0)
AND (steptwock3digit <= 189 OR steptwock3digit=0)
AND (steptwocs = 'PASS' OR steptwocs IS NULL)
AND (steponeattempt <= 1 OR steponeattempt=0)
AND (steptwockattempt <= 1 OR steptwockattempt=0)
AND (steptwocsattempt <= 2 OR steptwocsattempt=0)
AND ((USCEImportance = 'MAND' AND USCENoOfMonths<= '3') OR USCEImportance = 'PREF')
AND (yearsfrompassing >= 2 OR yearsfrompassing=0);
这是我在 PHP 中传递它的方式:
$sql = "SELECT * FROM `program_list`
WHERE
speciality LIKE '%%s%'
AND (stepone2digit <= %d OR stepone2digit=0)
AND (stepone3digit <= %d OR stepone3digit=0)
AND (steptwock2digit <= %d OR steptwock2digit=0)
AND (steptwock3digit <= %d OR steptwock3digit=0)
AND (steptwocs = '%s' OR steptwocs IS NULL)
AND (steponeattempt <= %d OR steponeattempt=0)
AND (steptwockattempt <= %d OR steptwockattempt=0)
AND (steptwocsattempt <= %d OR steptwocsattempt=0)
AND ((USCEImportance = 'MAND' AND USCENoOfMonths<= '%s') OR USCEImportance = 'PREF')
AND (yearsfrompassing >= %d OR yearsfrompassing=0)
当我运行原始查询时,它工作正常,但是当我插入变量并从 PHP 运行它时,没有返回任何结果。
我错过了什么?请帮忙。