Doctrine: ON DUPLICATE KEY UPDATE

Leonardo picture Leonardo · Dec 29, 2010 · Viewed 25.4k times · Source

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

Answer

artemiuz picture artemiuz · Jun 24, 2014

for Symfony 2 use raw sql:

$em->getConnection()->prepare("INSERT INTO table SET 
    some_fields = "some data", created_at = NOW() 
    ON DUPLICATE KEY UPDATE
    some_fields = "some data", updated_at = NOW()
")->execute();