-1

我收到以下错误。有人在我的代码中看到问题吗?谢谢。

警告:PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in (my file) on line 309 (the execute line)

注意:名称中带有“array”的变量不是实际的数组。

$STH = $DBH->prepare("select jp.jobpost_id,jp.zipcode FROM jobposts jp JOIN zipcodes zc ON jp.zipcode=zc.zipcode JOIN employers em ON jp.employerid=em.employerid WHERE MATCH (jp.description) AGAINST (:keyword IN BOOLEAN MODE) AND
                                   jp.empstage LIKE :active
                               AND jp.title LIKE :title
                               AND jp.level >= :minlevel
                               AND jp.level <= :maxlevel
                               AND jp.experience >= :minexperience
                               AND jp.experience <= :maxexperience
                               AND jp.travel >= :mintravel
                               AND jp.travel <= :maxtravel
                               AND jp.education >= :mineducation
                               AND jp.education <= :maxeducation
                               AND jp.clearance >= :minclearance
                               AND jp.clearance <= :maxclearance
                               AND jp.hiredate >= :minhiredate
                               AND jp.hiredate <= :maxhiredate
                               AND jp.startdate >= :minstartdate
                               AND jp.startdate <= :maxstartdate
                               AND jp.probhire >= :minprobhire
                               AND jp.probhire <= :maxprobhire
                               AND jp.probstaff >= :minprobstaff
                               AND jp.probstaff <= :maxprobstaff
                               AND jp.salaryhigh >= :minsalaryhigh
                               AND jp.salaryhigh <= :maxsalaryhigh
                               AND jp.hourlyhigh >= :minhourlyhigh
                               AND jp.hourlyhigh <= :maxhourlyhigh
                               AND jp.salaryfee >= :minsalaryfee
                               AND jp.salaryfee <= :maxsalaryfee
                               AND jp.hourlyfee >= :minhourlyfee
                               AND jp.hourlyfee <= :maxhourlyfee
                               AND jp.shortcontractor LIKE :array_shortcontractor
                               AND jp.longcontractor LIKE :array_longcontractor
                               AND jp.tempperm LIKE :array_tempperm
                               AND jp.permplacement LIKE :array_permplacement
                               AND jp.open LIKE :like
                               AND em.staffingco NOT LIKE :staffingco
                               ");

                                ////// get results not factoring in zip code
                                $STH->bindValue(':keyword', $keyword);
                                $STH->bindValue(':active', 'active');
                                $STH->bindValue(':title', $title);
                                $STH->bindValue(':minlevel', $minlevel);
                                $STH->bindValue(':maxlevel', $maxlevel);
                                $STH->bindValue(':minexperience', $minexperience);
                                $STH->bindValue(':maxexperience', $maxexperience);
                                $STH->bindValue(':mintravel', $mintravel);
                                $STH->bindValue(':maxtravel', $maxtravel);
                                $STH->bindValue(':mineducation', $mineducation);
                                $STH->bindValue(':maxeducation', $maxeducation);
                                $STH->bindValue(':minclearance', $minclearance);
                                $STH->bindValue(':maxclearance', $maxclearance);
                                $STH->bindValue(':minhiredate', $minhiredate);
                                $STH->bindValue(':maxhiredate', $maxhiredate);
                                $STH->bindValue(':minstartdate', $minstartdate);
                                $STH->bindValue(':maxstartdate', $maxstartdate);
                                $STH->bindValue(':minprobhire', $minprobhire);
                                $STH->bindValue(':maxprobhire', $maxprobhire);
                                $STH->bindValue(':minprobstaff', $minprobstaff);
                                $STH->bindValue(':maxprobstaff', $maxprobstaff);
                                $STH->bindValue(':minsalaryhigh', $minsalaryhigh);
                                $STH->bindValue(':maxsalaryhigh', $maxsalaryhigh);
                                $STH->bindValue(':minhourlyhigh', $minhourlyhigh);
                                $STH->bindValue(':maxhourlyhigh', $maxhourlyhigh);
                                $STH->bindValue(':minsalaryfee', $minsalaryfee);
                                $STH->bindValue(':maxsalaryfee', $maxsalaryfee);
                                $STH->bindValue(':minhourlyfee', $minhourlyfee);
                                $STH->bindValue(':maxhourlyfee', $maxhourlyfee);
                                $STH->bindValue(':array_shortcontractor', $array_shortcontractor);
                                $STH->bindValue(':array_longcontractor', $array_longcontractor);
                                $STH->bindValue(':array_tempperm', $array_tempperm);
                                $STH->bindValue(':array_permplacement', $array_permplacement);
                                $STH->bindValue(':open', $open);
                                $STH->bindValue(':staffingco', $staffingco);
                                $STH->execute();
4

1 回答 1

2

这是 MySQL 的一个奇怪特性,但您不能在MATCH() AGAINST().

您必须在之前插入字符串,prepare()因此它是 SQL 查询中的字符串文字。请务必使用PDO::quote()以确保正确转义特殊字符。

例子:

$keyword_quoted = $DBH->quote($keyword);

$STH = $DBH->prepare("select jp.jobpost_id,jp.zipcode 
  FROM jobposts jp 
  JOIN zipcodes zc ON jp.zipcode=zc.zipcode 
  JOIN employers em ON jp.employerid=em.employerid 
  WHERE MATCH (jp.description) AGAINST ($keyword_quoted IN BOOLEAN MODE) AND
  . . .

当然你也可以跳过bindValue($keyword)

于 2013-02-11T03:20:45.510 回答