Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MarkTierney's avatar

Is REPLACE INTO possible in the Query Builder or Eloquent?

Currently I have a table with thousands of entries and only a primary key (no indexes) so mass updates take forever.

I'm currently finding all relevant entries, deleting them and then doing a mass insert of the updated records as the id isn't really important.

I know this is normally something I could do with REPLACE INTO in MySQL, I just wondered if there's a way of doing using built in functions, I can't seem to find anything.

0 likes
2 replies
Cronix's avatar

Sure, just use RAW statements and write it out like you normally would. Both query builder and eloquent have methods for executing raw sql. There isn't anything built in, because not all database engines support it. ORM's usually only cater to the lowest common denominator (commands all db engines support), so they tend to be pretty basic.

MarkTierney's avatar

Thanks, yes raw is always an option. I'm not sure how much benefit there will be refactoring from my current scenario (find matches, delete, then insert new) to using replace into. Only one way to find out :-)

Please or to participate in this conversation.