无法使用类似的绑定自定义正则表达式



我在使用bindparam时无法使用自定义的reg-ex创建查询。

这是我的代码:

public function findAllByTag($tag)
    {
        $expressionOne = $tag.",%";
        $expressionTwo = "%,".$tag;
        $expressionThree = "%,".$tag.",%";
        $expressionFour = $tag;
        $query  = "SELECT * FROM Conditions WHERE  ";/*'CONCAT(:tag, ',%')*/
        $clause = "(tag LIKE :expressionOne || tag LIKE :expressionTwo || tag LIKE :expressionThree|| tag LIKE :expressionFour)";
        $query .= $clause;
        $boundParams[0] = $query;
        $stmt           = $this->getPreparedStatement($query);
        $stmt->bindParam(':expressionOne', $expressionOne, PDO::PARAM_STR);
        $stmt->bindParam(':expressionTwo', $expressionTwo, PDO::PARAM_STR);
        $stmt->bindParam(':expressionThree', $expressionThree, PDO::PARAM_STR);
        $stmt->bindParam(':expressionFour', $expressionFour, PDO::PARAM_STR);
        $boundParams[0] = $query;
        $stmt->execute($boundParams);
        $collection = new Collection();
        while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $collection->add($this->createObject($data));
        }
        $collection->resetChanges();
        return $collection;
    }

它在下面的代码中引发了错误:'期望']":

class ExceptionResponse extends Response
{
    /**
     * It prepares response message from message and code of exception, statusCode is initialized to exception code and
     * message is an array of code and message of format {_errors: [ {'code' : int, 'message': string }, .. ]}
     *
     * @param Exception $e exception from which return response will be created
     */
    public function __construct(Exception $e)
    {
        if (!($e instanceof GenericException)) {
            $e = new GenericException($e->getMessage());
        }
        $data = [
            'error' => true,
            'failure' => [
                [
                    'code'    => $e->getCode(),
                    'message' => $e->getMessage(),
                ],
            ],
            'success': null
        ];
        $this->setHeader('Content-Type', 'application/json');
        $this->setMessage(json_encode($data));
        $this->setStatusCode($e->getCode());
    }
}

行#39:'success': null

如何删除此错误并使查询工作?注意:我正在使用公司,格里芬和编写代码的框架。一切都很好,但是bindparam。

我尝试使用bindvalues,它工作正常。

        $expressionOne = $tag.",%";
        $expressionTwo = "%,".$tag;
        $expressionThree = "%,".$tag.",%";
        $expressionFour = $tag;
        $clause = "(tag LIKE :expressionOne || tag LIKE :expressionTwo || tag LIKE :expressionThree|| tag LIKE :expressionFour)";
        $query  = "SELECT * FROM Conditions WHERE ";
        //$clause = "(tag LIKE :expressionOne)";
        $query .= $clause;
        $boundParams[0] = $query;
        $stmt           = $this->getPreparedStatement($query);
        //$stmt->bind_param("s", $tag);
        $stmt->bindValue(':expressionOne', $expressionOne, PDO::PARAM_STR);
        $stmt->bindValue(':expressionTwo', $expressionTwo, PDO::PARAM_STR);
        $stmt->bindValue(':expressionThree', $expressionThree, PDO::PARAM_STR);
        $stmt->bindValue(':expressionFour', $expressionFour, PDO::PARAM_STR);

最新更新