带 LIMIT 的 Doctrine 更新查询

标签 doctrine doctrine-orm doctrine-query

我想用这样的 LIMIT 进行更新查询:

UPDATE anytable SET anycolumn = 'anyvalue' WHERE anothercolumn='anothervalue' LIMIT 20

这怎么可能用 Doctrine 2.1 实现?

最佳答案

我发现我必须从entityManager获取连接并调用executeUpdate:

$em->getConnection()->executeUpdate(
    "UPDATE anytable SET anycolumn = 'anyvalue'
     WHERE anothercolumn='anothervalue'
     LIMIT 20");

doctrine page about native queries说:

If you want to execute DELETE, UPDATE or INSERT statements the Native SQL API cannot be used and will probably throw errors. Use EntityManager#getConnection() to access the native database connection and call the executeUpdate() method for these queries.

关于带 LIMIT 的 Doctrine 更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8893234/

相关文章:

php - 如何防止 EntityManager (Doctrine Association) 删除

forms - Symfony2 表单和 Doctrine2 - 更新分配实体中的外键失败

php - 使用数组的 Doctrine 查询生成器

php - ORM-ManyToMany 关系中的附加字段

symfony - 如何在 findAll() 中获取数组结果 - Doctrine?

Symfony2 : deleted property still used in query

php - 数据库 ORM Doctrine Symfony 4

php - 既然不推荐使用 fetchAll() 和 FetchMode,如何将结果提取到自定义对象中?

php - 在 symfony 中设置默认时区

mysql - 如何查看查询中的参数?