0

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?

Amo
  • 2,884
  • 5
  • 24
  • 46

1 Answers1

1

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)

Community
  • 1
  • 1
Corbin
  • 33,060
  • 6
  • 68
  • 78
  • Perfect! Thank you for that. I couldn't actually see where that was outlined in the PDO manual on php.net. – Amo Dec 02 '12 at 08:03