Reputation: 8360
I'm using Doctrine 2 with PDO_MYSQL and I want to query that query:
SELECT DISTINCT DATE_FORMAT(FROM_UNIXTIME(time), '%M %Y')
FROM Project\Posts
GROUP BY time
So I tried that:
$q = $em->createQuery("SELECT DISTINCT DATE_FORMAT(FROM_UNIXTIME(time), '%M %Y') FROM Project\Posts GROUP BY time");
$r = $q->getResult();
print_r($r);
But I get this error:
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 16: Error: Expected known function, got 'DATE_FORMAT''
So how could I query that query?
Upvotes: 0
Views: 1838
Reputation: 44376
In this case you should bypass ORM and work on DBAL layer, cause you're not doing any mapping.
$stmt = $dbal->execute('SQL (not DQL!) here');
$dates = $stmt->fetchAll();
Upvotes: 3