I have the following code:
$repository = $this->entitymanager->getRepository('Intlist\Entity\Location');
$query = $repository->createQueryBuilder('l')
->select('l.country')
->groupBy('l.country')
->where('l.country != :empty_country')
->setParameter('empty_country', "")
->getQuery();
And I would like to obtain something like [ 'EN', 'FR', 'US' ]
, like PDO::FETCH_COLUMN
would return. I tried getScalarResult()
but it returns the same result as getArrayResult()
:
array (size=2)
0 =>
array (size=1)
'country' => string 'DE' (length=2)
1 =>
array (size=1)
'country' => string 'MM' (length=2)
I tried to use execute()
as I have seen on some examples but it returns the same result as getArrayResult()
and not a PDO statement.
Any idea?
You can extract values from your query result to get the array you want :
If you want native results, you can make a custom hydration mode, as explained in Doctrine doc.
Create a class extending AbstractHydrator:
Add the class to the ORM configuration:
Then use it: