使用 Doctrine NativeQuery 获取单行结果
2022-08-30 09:32:37
我正在尝试从带有 Doctrine 的本机查询返回一行。这是我的代码:
$rsm = new ResultSetMapping;
$rsm->addEntityResult('VNNCoreBundle:Player', 'p');
$rsm->addFieldResult('p', 'player_id', 'id');
$sql = "
SELECT player_id
FROM players p
WHERE CONCAT(p.first_name, ' ', p.last_name) = ?
";
$query = $this->getEntityManager()->createNativeQuery($sql, $rsm);
$query->setParameter(1, $name);
$players = $query->getResult();
最后一行返回玩家列表,但我只想要一个结果。我该怎么做?