How to use like token?

this->modelsManager->createBuilder() ->from(array('g' => 'Goods')) ->join('Enterprises','g.enterpriseid = e.id','e') ->where('g.categoryid = :id:',array('id' => $categoryid)) ->andWhere("e.fullname like '%:keyword:%'",array('keyword' => $keyword)) ->getQuery() ->execute();

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



83.4k

This way:

$this->modelsManager->createBuilder()
    ->from(array('g' => 'Goods'))
    ->join('Enterprises','g.enterprise_id = e.id','e')
    ->where('g.category_id = :id:',array('id' => $category_id))
    ->andWhere("e.full_name like :keyword:",array('keyword' => '%'. $keyword. '%'))
    ->getQuery()
    ->execute();