Search code examples
mysqlsymfonydql

Doctrine get result issue


I got DQL like this:

$sql =$qb->select('c')
->from('Cusomter','c')
->where('c.login = :login')
->setParameter('login',$login);
$rs = $sql->getQuery()->getResult(Query::HYDRATE_OBJECT);

But I got the following error

Fatal error: Class 'customer\Query' not found in MyNameSpace\customer.php

Do i need to use any namespace?
Thanks.


Solution

  • you dont need to actually tell getResult to hydrate_object, its default behaviour, and therefore called from the method itself.

    try:

    $rs = $sql->getQuery()->getResult();
    

    if you want to know the right namespace for the constant though its:

    Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT