原则:关于重复键更新 [英] Doctrine: ON DUPLICATE KEY UPDATE

查看:63
本文介绍了原则:关于重复键更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用选项ON DUPLICATE KEY UPDATE编写INSERT学说?

How can I write an INSERT doctrine query with option ON DUPLICATE KEY UPDATE?

推荐答案

问题是,这是MySQL特有的问题,因此教义不会直接覆盖它.

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.

这篇关于原则:关于重复键更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆