学说:关于重复密钥更新

Doctrine: ON DUPLICATE KEY UPDATE(学说:关于重复密钥更新)
本文介绍了学说:关于重复密钥更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写带有选项 ON DUPLICATE KEY UPDATEINSERT 条令查询?

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.

如果您希望它更复杂且真正独立于数据库,请查看 事件 和它的可能性.在执行实际查询之前,您可以检查是否存在,如果存在,则采取相应措施.

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.

这篇关于学说:关于重复密钥更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)