I am trying to execute a MySQL statement. The variable clause has the where
clause. The query was working fine until I used bindParam. From the documentation, there have been instances of LIKE
being used. However, I am still unclear as to why my query returns null. I think the flaw is in using the :tag
in the $clause
.
public function findAllByTag($tag)
{
$query = "SELECT * FROM Conditions WHERE ";
$clause = "(tag LIKE ':tag,%' || tag LIKE '%,:tag' || tag LIKE '%,:tag,%' || tag LIKE ':tag')";
$query .= $clause;
$boundParams[0] = $query;
$stmt = $this->getPreparedStatement($query);
$stmt->bindParam(':tag', $tag, \PDO::PARAM_STR, 100);
$stmt->execute($boundParams);
$collection = new Collection();
while ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$collection->add($this->createObject($data));
}
$collection->resetChanges();
return $collection;
}