我正在尝试执行MySQL语句。 variable子句具有where
子句。查询工作正常,直到我使用bindParam。从文档中可以看到LIKE
被使用的实例。但是,我仍然不清楚为什么我的查询返回null。我认为缺陷在于使用:tag
中的$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;
}