doctrine dbal querybuilder as prepared statement

前端 未结 5 2009
故里飘歌
故里飘歌 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 18:05

    try this:

    $qb->where('tbl_user.pkid = :userid');
    $qb->setParameter(':userid', 10);
    

    then

     $params = $qb->getParameters();
     $stmt = $connection->prepare($qb->getSQL());
     foreach ($params as $key=>$value){
        $stmt->bindParam($key,$value);
     }
    
    $stmt->execute();
    $result = $stmt->fetchAllAssociative();
    

提交回复
热议问题