Get single row result with Doctrine NativeQuery

后端 未结 6 533
独厮守ぢ
独厮守ぢ 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

    I just want one result

    implies that you expect only one row to be returned. So either adapt your query, e.g.

    SELECT player_id
    FROM players p
    WHERE CONCAT(p.first_name, ' ', p.last_name) = ?
    LIMIT 0, 1
    

    (and then use getSingleResult() as recommended by AdrienBrault) or fetch rows as an array and access the first item:

    // ...
    $players = $query->getArrayResult();
    $myPlayer = $players[0];
    

提交回复
热议问题