Get single row result with Doctrine NativeQuery

后端 未结 6 519
独厮守ぢ
独厮守ぢ 2020-12-15 02:26

I\'m trying to get a single row returned from a native query with Doctrine. Here\'s my code:

$rsm = new ResultSetMapping;
$rsm->addEntityResult(\'VNNCoreB         


        
6条回答
  •  轮回少年
    2020-12-15 03:19

    You can use $query->getSingleResult(), which will throw an exception if more than one result are found, or if no result is found. (see the related phpdoc here https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/AbstractQuery.php#L791)

    There's also the less famous $query->getOneOrNullResult() which will throw an exception if more than one result are found, and return null if no result is found. (see the related phpdoc here https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/AbstractQuery.php#L752)

提交回复
热议问题