当我手动应用需要引用%的正则表达式时,如何bindParam?

时间:2018-02-08 07:47:46

标签: php mysql

我正在尝试执行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;
    }

0 个答案:

没有答案