Doctrine: ON DUPLICATE KEY UPDATE(教义:重复密钥更新)
问题描述
如何使用选项 ON DUPLICATE KEY UPDATE 编写 INSERT 原则查询?
How can I write an INSERT doctrine query with option ON DUPLICATE KEY UPDATE?
推荐答案
问题是这是 MySQL 特有的问题,因此 Doctrine 不会直接涵盖.
The problem is that this is a MySQL specific problem so it will not be directly covered by Doctrine.
正如评论所提到的,您需要为此编写一个 RawSQL 查询.这将是最简单的方法.
As a comment mentioned, you would need to write a RawSQL Query for this. This would be the easiest way.
如果您希望它更复杂且真正独立于数据库,请查看 Events 和它的可能性.在执行实际查询之前,您可以检查是否存在,如果存在,则采取相应措施.
If you want it more sophisticated and truely DB independent, look into Events and it's possibilities. Before the actual query is executed, you can check for an existence and if it exists, act accordingly.
一种独立于 ORM/PHP 的方式是编写一个存储过程/触发器来处理这个问题的数据库端.
An ORM/PHP independent way is to write a stored procedure/trigger that handles this problem database side.
这篇关于教义:重复密钥更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:教义:重复密钥更新
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
