doctrine dbal querybuilder as prepared statement

前端 未结 5 2063
故里飘歌
故里飘歌 2021-01-16 17:25

I\'m trying to create a Doctrine DBAL querybuilder object and setting a parameter in it. (using a postgres db, dbal 2.3.4, doctrine

$connection = $this->         


        
5条回答
  •  情深已故
    2021-01-16 17:57

    The setParameter part of your querybuillder function is wrong. You do not need the :, you can put it all on one line like this, and only include one talbe in your FROM statement. You may have a problem in your JOIN or FROM statement if there is another table named tbl_user and need to check your entity definitions to make sure the annotations are correct.

    $connection = $this->_em->getConnection();
    $qb = $connection->createQueryBuilder();
    $qb->select('tbl_user_contract.pkid AS pkid')
      ->from('tbl_user_contract')
      ->join('tbl_user_contract', 'tbl_user', 'tbl_user', 'tbl_user_contract.fk_user =   tbl_user.pkid')
      ->where('tbl_user.pkid = :userid')
      ->setParameter('userid', 10);
    

    Refer to the docs here http://docs.doctrine-project.org/en/latest/reference/query-builder.html#binding-parameters-to-your-query.

提交回复
热议问题