Invalid Parameter Number - PDO

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chris98
Forum Contributor
Posts: 103
Joined: Tue Jun 11, 2013 10:47 am
Location: England, United Kingdom

Invalid Parameter Number - PDO

Post by chris98 »

I'm trying to create a better search query from another topic that searches the article content and title but it returns:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number' in /home/directories/:110 Stack trace: #0 /home/directories/(110): PDOStatement->execute(Array) #1 {main} thrown in /home/directories/ on line 110

Code: Select all

$count = "SELECT COUNT(*) AS id FROM pages WHERE title LIKE :search AND sub_page != 'sub_sub_page' AND site = :site OR text LIKE :search AND site = :site AND sub_page != 'sub_sub_page'";
	$shn_sites->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
	$ps = $shn_sites->prepare($count);
	$ps->execute(array( 
	':search'=>'%' . $search_results . '%',
	':site'=>$site));
EDIT: Never mind, I used different parameters and it worked. I don't know why though.
Post Reply