I want to get the columns selected in query if no data are returned
$sql = $this->em->getConnection()->prepare('
SELECT
DATE_FORMAT(cus.period, "%Y") as ANNEE,
DATE_FORMAT(cus.period, "%m") as MOIS,
c.name AS PAYS,
co.id AS ORIGINE_ID,
co.name AS ORIGINE,
FROM customs AS cus
WHERE cp.product in (503)
GROUP BY ANNEE, MOIS, PRODUCT, co.id , c.id
ORDER BY ANNEE, MOIS, CAMPAGNE, PRODUCT, co.id, c.name;'
);
$sql->execute();
$result = $sql->fetchAll();
I no data the result is an empty array, but I want in case that no data result should be an array like
$result = [
'ANNEE', 'MOIS', 'PAYS', 'ORIGINE_ID', 'ORIGINE'
]
UNION
in the query which first selects static values for the column names. But why? It seems like whatever you want to do there's likely a better way to do it.