4

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?

2 Answers 2

8

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();
Sign up to request clarification or add additional context in comments.

1 Comment

You always need to define an alias.
0

What worked for me is using Exp with ->set() like $qb->expr()

$qb = $this->em->createQueryBuilder();
$q = $qb->update('models\User', 'u')
        ->set('u.username', $qb->expr()->literal($username))
        ->set('u.email', $qb->expr()->literal($email))
        ->where('u.id = ?1')
        ->setParameter(1, $editId)
        ->getQuery();
$p = $q->execute();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.