尝试使用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();
我做错了什么?
答案 0 :(得分:6)
添加别名
时似乎可以正常工作$query = $em->createQuery('
SELECT u.username
FROM BLOGBlogBundle:user u
WHERE u.username = :usrname')
->setParameter('usrname', $usr);
$products = $query->getResult();
答案 1 :(得分: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();