Saturday, 15 January 2011

PDO PHP Error - Invalid Parameter Number -



PDO PHP Error - Invalid Parameter Number -

i'm getting next error. see issue in code? thanks.

warning: pdostatement::execute() [pdostatement.execute]: sqlstate[hy093]: invalid parameter number: parameter not defined in (my file) on line 309 (the execute line)

note: variables "array" in name not actual arrays.

$sth = $dbh->prepare("select jp.jobpost_id,jp.zipcode jobposts jp bring together zipcodes zc on jp.zipcode=zc.zipcode bring together employers em on jp.employerid=em.employerid match (jp.description) against (:keyword in boolean mode) , jp.empstage :active , jp.title :title , jp.level >= :minlevel , jp.level <= :maxlevel , jp.experience >= :minexperience , jp.experience <= :maxexperience , jp.travel >= :mintravel , jp.travel <= :maxtravel , jp.education >= :mineducation , jp.education <= :maxeducation , jp.clearance >= :minclearance , jp.clearance <= :maxclearance , jp.hiredate >= :minhiredate , jp.hiredate <= :maxhiredate , jp.startdate >= :minstartdate , jp.startdate <= :maxstartdate , jp.probhire >= :minprobhire , jp.probhire <= :maxprobhire , jp.probstaff >= :minprobstaff , jp.probstaff <= :maxprobstaff , jp.salaryhigh >= :minsalaryhigh , jp.salaryhigh <= :maxsalaryhigh , jp.hourlyhigh >= :minhourlyhigh , jp.hourlyhigh <= :maxhourlyhigh , jp.salaryfee >= :minsalaryfee , jp.salaryfee <= :maxsalaryfee , jp.hourlyfee >= :minhourlyfee , jp.hourlyfee <= :maxhourlyfee , jp.shortcontractor :array_shortcontractor , jp.longcontractor :array_longcontractor , jp.tempperm :array_tempperm , jp.permplacement :array_permplacement , jp.open :like , em.staffingco not :staffingco "); ////// 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();

it's unusual idiosyncrasy of mysql, can't utilize query parameter placeholder in arguments match() against().

you have interpolate string before prepare() it's string literal in sql query. sure utilize pdo::quote() ensure proper escaping of special characters.

example:

$keyword_quoted = $dbh->quote($keyword); $sth = $dbh->prepare("select jp.jobpost_id,jp.zipcode jobposts jp bring together zipcodes zc on jp.zipcode=zc.zipcode bring together employers em on jp.employerid=em.employerid match (jp.description) against ($keyword_quoted in boolean mode) , . . .

and of course of study can skip bindvalue($keyword).

php pdo

No comments:

Post a Comment