【问题标题】:Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got 'ON'错误:预期的 Doctrine\ORM\Query\Lexer::T_WITH,得到 'ON'
【发布时间】:2013-12-26 08:58:11
【问题描述】:

我编写了以下代码用于从数据库中获取数据:

function getnotificationAction()
{
    $session = $this->getRequest()->getSession();
    $userId = $session->get('userid');

    $entitymanager = $this->getDoctrine()->getEntityManager();
    $notification = $entitymanager->getRepository('IGCNotificationBundle:Notifications');
    $userNotification = $entitymanager->getRepository('IGCNotificationBundle:Usernotifications');
    $query = $entitymanager
                 ->createQuery("SELECT n.notificationid, n.title,n.notificationmessage, u.creationdate, u.notificationid, u.messagestatus From IGCNotificationBundle:Notifications AS n JOIN IGCNotificationBundle:Usernotifications AS u ON u.notificationid = n.notificationid WHERE u.userId = :userId ORDER BY n.creationdate DESC")->setParameter('userId', userId);

    $notifications = $query->getResult();

    return $this->render('IGCNotificationBundle:Default:notification.html.twig', array('notifications' => $notifications));
} }

但它正在给予:

[语法错误] 第 0 行,第 203 列:错误:预期 Doctrine\ORM\Query\Lexer::T_WITH,得到 'ON' 500 内部服务器错误 - QueryException 1 链接异常:QueryException »

【问题讨论】:

  • 可能会被删除 AS IGCNotificationBundle:Notifications n JOIN IGCNotificationBundle:Usernotifications u
  • 您好,感谢您的回复,我已经尝试过了,但遇到了同样的错误
  • 据我所知,您正在尝试执行SQL...您需要将其重写为DQL(Docrine Query Language)。请用实体的结构更新您的问题...
  • 嗨 @jperovic 我不知道如何在 DQL 中转换它
  • 任何人都可以在dql查询中转换这个sql查询

标签: php symfony doctrine-orm


【解决方案1】:
[Syntax Error] line 0, col 203: Error: Expected Doctrine\ORM\Query\Lexer::T_WITH, got 'ON' 500 Internal Server Error - QueryException 1 linked Exception: QueryException »

我认为您应该将关键字“ON”替换为“WITH”。

从文档中提取:

现在可以在 DQL 中通过使用 语法FROM Foo f JOIN Bar b WITH f.id = b.id

【讨论】:

  • 是的,我对 Symfony 3 原则也有同样的问题,它有效。必须使用WITH 而不是ON
【解决方案2】:

请使用下面的代码为您工作

function getnotificationAction() {
    $session = $this->getRequest()->getSession();
    $userId = $session->get('userid');
    $entitymanager = $this->getDoctrine()->getEntityManager();
    $notification = $entitymanager->getRepository('IGCNotificationBundle:Notifications');
    $userNotification = $entitymanager->getRepository('IGCNotificationBundle:Usernotifications');
    $query = $entitymanager->createQuery("SELECT n.notificationid, n.title,n.notificationmessage, u.creationdate, u.notificationid, u.messagestatus From IGCNotificationBundle:Notifications AS n JOIN IGCNotificationBundle:Usernotifications AS u WITH u.notificationid = n.notificationid WHERE u.userId = :userId ORDER BY n.creationdate DESC")->setParameter('userId', userId);
    $notifications = $query->getResult();
    return $this->render('IGCNotificationBundle:Default:notification.html.twig', array('notifications' => $notifications));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-17
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    相关资源
    最近更新 更多