Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 error Expected end of string

Trying to run a query with symfony and I get this error:

[Syntax Error] line 0, col 83: Error: Expected end of string, got 'username'

This code throws that error:

$query = $em->createQuery(
            'SELECT username
            FROM BLOGBlogBundle:user
            WHERE username= :usrname'
        )->setParameter('usrname', $usr);
        $products = $query->getResult();

What am I doing wrong?

like image 357
SDWACW Avatar asked Feb 16 '23 21:02

SDWACW


1 Answers

Seems to work when you add in the alias

$query = $em->createQuery('
            SELECT u.username
            FROM BLOGBlogBundle:user u
            WHERE u.username = :usrname')
    ->setParameter('usrname', $usr);

$products = $query->getResult();
like image 174
Ken Hannel Avatar answered Feb 18 '23 13:02

Ken Hannel