【问题标题】:Should I use Connection::executeUpdate()?我应该使用 Connection::executeUpdate() 吗?
【发布时间】:2015-02-06 00:33:02
【问题描述】:

我使用 Doctrine DBAL v2.5.0,我想执行一个简单的更新语句。在文档中写道,我应该为此使用方法 executeUpdate() (http://doctrine-dbal.readthedocs.org/en/latest/reference/data-retrieval-and-manipulation.html#executeupdate)。但是在源代码中这个方法有注解@internal。因此,我不确定是否应该从非库代码中使用此方法。我应该吗?

【问题讨论】:

    标签: doctrine-orm dbal


    【解决方案1】:

    看来您必须在教义服务上使用executeUpdate() 方法,而不是在实体管理器上。

    $this->container->get('doctrine.orm.entity_manager')->getConnection()->executeUpdate($query); 在我的 IDE 中发出警告,指出 executeUpdate() 是 @internal。

    $this->container->get('doctrine')->getConnection()->executeUpdate($query); 或在控制器中$this->getDoctrine()->getConnection()->executeUpdate($query); 不发出任何警告。

    换句话说: 你想调用 executeUpdate() 方法 \Doctrine\Bundle\DoctrineBundle\Registry班级 而不是 \Doctrine\ORM\EntityManager

    P.D.也许我应该提到我正在将 Doctrine 与 Symfony2 结合使用。

    【讨论】:

    • 非常感谢您的回答!但我不确定:$this->container->get('doctrine.orm.entity_manager') 给出了一个Doctrine\ORM\EntityManager 对象和$this->container->get('doctrine') 一个Doctrine\Bundle\DoctrineBundle\Registry 对象。但是当我打电话给getConnection() 时,在这两种情况下我都会得到Doctrine\DBAL\Connection,所以我最终遇到了同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2021-12-10
    • 2010-12-25
    • 2014-05-27
    • 2010-12-25
    相关资源
    最近更新 更多