doctrine 2 querybuilder with set parameters not working

前端 未结 2 1365
春和景丽
春和景丽 2021-01-23 09:19

this is my query:

public function getDetails($userid, $orderby, $sort){

$query = $this->_em->createQueryBuilder()
                ->select(\'u\'         


        
2条回答
  •  广开言路
    2021-01-23 09:53

    You cant bind parameters to QueryBuilder, only to Query, so just swap lines, first get query out of builder, then fill it with parameters and get result.

    $query = $this->_em->createQueryBuilder()
                ->select('u')
                ->from('\Entities\Users', 'u')
                ->where('u.userid= ?1')
                ->orderBy('u.?3', '?3')
                ->orderBy('u.'.$orderBy, $sort)
                ->getQuery()
                ->setParameter(1, $userid)
                ->getResult();
    
    }
    

    In doctrine 2.4 its fixed, and you can bind parameters to QueryBuilder.

    Update: i've missed moment with placeholder in field name, SQL do not support such constructions.

提交回复
热议问题