Domanda

Sto usando Doctrine 2 con pdo_mysql e voglio interrogare che query:

SELECT DISTINCT DATE_FORMAT(FROM_UNIXTIME(time), '%M %Y')
FROM Project\Posts
GROUP BY time

Così ho provato che:

    $q = $em->createQuery("SELECT DISTINCT DATE_FORMAT(FROM_UNIXTIME(time), '%M %Y') FROM Project\Posts GROUP BY time");
    $r = $q->getResult();
    print_r($r);

Ma ottengo questo errore:

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 16: Error: Expected known function, got 'DATE_FORMAT''

Quindi, come ho potuto interrogare quella query?

È stato utile?

Soluzione

In questo caso si dovrebbe bypass ORM e lavorare su strato DBAL, perché sei non fare alcuna mappatura.

$stmt = $dbal->execute('SQL (not DQL!) here');
$dates = $stmt->fetchAll();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top