How to bindValue with% in PDO?

$query = $connect->prepare("SELECT users.firstname, users.lastname, users.id FROM users INNER JOIN users_friends ON users.id=users_friends.uID WHERE bID=:USER AND type =:type AND accepted = '1' AND (users.firstname LIKE '%:queryString%' OR users.lastname LIKE '%:queryString%') LIMIT 10"); $query->bindValue(":queryString", $queryString); $query->bindValue(":type", $type); $query->bindValue(":USER", $USER); $query->execute(); 

This is what I have.

I have an error when I try to bind a Value and then use it in a prepared statement (%: queryString%)

 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' 

How can i solve this?

+7
source share
1 answer

You have to do

 "... LIKE :query ..." 

and then

 $query->bindValue(":query", $queryString); //where $queryString is '%someQuery%' 
+11
source

All Articles