We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to use like token?

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();

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



98.9k

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();


12.8k