Do you know how I can make to get the sql from my createQueryBuilder ?
My Entity/DownloadRepository.php class:
public function getLastDownload($limit)
{
$query = $this->createQueryBuilder('d');
$query->select('l.ytId, d.title, d.date, d.id, l.creator')
->from('DimiYvmBundle:Log', 'l')
->where('d.ytId = l.ytId AND l.creator = :creator')
->orderBy('l.id', 'DESC')
->groupBy('l.ytId')
->setParameter('creator', 'n')
->setMaxResults($limit);
// echo $query->getSQL(); => Doesn't work...
return $query->getQuery()->getResult();
}
Thanks you all for your help. Best regards
EDIT
To get the sql, you have to make :
echo $query->getQuery()->getSql();
Thanks all !
You can get from $query->getQuery()->getSQL()
Just keep in mind that for the parameters it will produce ? instead of the value.
If you want to get the full SQL query with the parameters and values check the profiler tool bar in DEV mode of your page in browser.
You need to call getSql()
on getQuery()
object
echo $query->getQuery()->getSql();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With