我想用这样的 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/