简体   繁体   中英

PDO (mysql) Invalid parameter number: parameter was not defined

I've found so many existing questions asking about this error but none of them relate to my code's situation so despite searching for a while I've had to start a new question.

I'm writing a PDO prepared statement in PHP and i'm getting the error code:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in... 

The query that has been build so far is:

SELECT * FROM esl_comments, esl_articles WHERE esl_comments.commentSet=:esl_comments.commentSet AND esl_comments.commentSetInstanceID=:esl_comments.commentSetInstanceID AND esl_comments.commentVisible=:esl_comments.commentVisible AND esl_comments.commentID=:esl_comments.commentID;

And the data is being passed to the function which attempts to execute the query just fine. I've echo'ed it and it appears as:

esl_comments.commentSet - article
esl_comments.commentSetInstanceID - esl_articles.articleID
esl_comments.commentVisible - Y
esl_comments.commentID - 2

So there are four placeholders in the query, and all four are being satisfied with data but when I try to execute the query after binding it is giving the above error.

Does anyone have any ideas what may be causing it?

Placeholders must be alphanumeric or underscore.

:esl_comments.commentSet is not a valid placeholder. Try just :commentSet instead.

(And of course the other ones will need to be replaced as well)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM