Reputation: 10095
$query = $this->getEntityManager()->createQuery('
SELECT COUNT(s) FROM MyDiaryBundle:TrainingSession s
WHERE s.status = :completed
AND s.user = :user')
->setParameter('user',$user)
->setParameter('completed','confirmed');
$result = $query->getResult();
RESULT : array(1) { [0]=> array(1) { [1]=> string(1) "0" } }
And why is the nested array keyed with '1' ?
Upvotes: 0
Views: 771
Reputation: 1988
Use $query->getSingleScalarResult()
To answer your question – as far as I know, getResult() will hydrate an array of entities, so the first dimension holds the list of entities, and the 2nd dimension is the entity as well as any additional fields that are not part of the entity (such as the result of COUNT(s)).
The nested array element is probably keyed with '1' because you haven't provided as alias for the COUNT(s), such as COUNT(s) AS sessionCount.
Upvotes: 1