Uhhh... Why are you jumping forward to NativeSQL already? That kinda
defeats the advantage of using the ORM almost completely, at least for
those simple queries.

Did you validate your mappings first? Are they in sync with your DB?

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 3 February 2014 14:29, Nima Sadjadi <[email protected]> wrote:

> Yes, when I added
> protected $clientId;
> the error message I said in prev. email is fixed and client_id coloumn
> exists on prefix_clients table. Now I need to run a simple NativeSQL
> to see if it works,
> I have this:
>
> <?php
>
> require_once "bootstrap.php";
> require_once "entities/clients.php";
>
> use Doctrine\ORM\Query\ResultSetMapping;
>
> $rsm = new Doctrine\ORM\Query\ResultSetMapping();
> // build rsm here
> $qb = $em->createQueryBuilder();
> $query = $qb->getQuery();
> $query = $em->createNativeQuery('SELECT first_name FROM prefix_clients
> WHERE username = ?', $rsm);
> $query->setParameter(1, 'blad');
> $array = $query->getArrayResult();
> print_r($array);
>
> I get a blank array, no result returns.
>
> and if I use this:
>
> $class = $em->getClassMetadata('Entities\clients');
> //$class = $em->getMetadataFactory()->getMetadataFor('Entities\clients');
>
> $rsm = new Doctrine\ORM\Query\ResultSetMapping;
> $rsm->addEntityResult('Entities\clients', 'u');
> $rsm->addFieldResult('u', 'client_id', 'clientId');
> rsm->addFieldResult('u', 'first_name', 'firstName');
> $query = $em->createNativeQuery('SELECT client_id, first_name FROM
> prefix_clients WHERE username = ?', $rsm);
> $query->setParameter(1, 'evident');
> $users = $query->getResult();
> print_r($users);
>
> I get a blank array, no result returns.
>
> as about the addFieldResult, the second param is coloumn name and 3rd
> param is fieldname that I've added protected $blah; in entity file.
> Also I did check if WHERE clause and setParameter is valid and a
> result is expected to be reurned but nothing returned, please advice.
>
> Please advice.
>
> --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to