4

尝试使用 symfony 运行查询,但出现此错误:

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

此代码引发该错误:

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

我究竟做错了什么?

4

2 回答 2

8

添加别名时似乎有效

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

$products = $query->getResult();
于 2013-07-16T19:17:12.700 回答
0

对我有用的是Exp使用->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();
于 2017-11-13T06:28:10.027 回答