Just found $this->db->replace() |
Oh my god, I was just checking something obvious about Query Builder return values for Update when I saw this thing:
$this->db->replace() Wow. Quite simply the most useful function that up to now I have overlooked. Just wanted to say how much I love this function. ![]() Paul.
(07-24-2015, 10:22 AM)PaulD Wrote: Oh my god, I was just checking something obvious about Query Builder return values for Update when I saw this thing: I use it a lot, too. But a replace_batch() would be even better.
(08-05-2015, 10:22 AM)ivantcholakov Wrote: http://code.openark.org/blog/mysql/repla...hink-twice I tend to make use of it on tables used to store multilanguage content. As with site pages, for instance. They usually have a structure with UNIQUE (article_id, lang) plus title, content, etc. , where article_id is a forein key for an articles table and lang is the language code, so a REPLACE INTO will not break any relation on the database. Those tables have no primary keys themselves. (08-05-2015, 10:22 AM)ivantcholakov Wrote: http://code.openark.org/blog/mysql/repla...hink-twice Interesting read - thank you. Having used the function now, even given the warnings and usage limitations about auto increments changing and possible overhead, it is still a fantastic function IMHO. Has made so many bits of my code so much cleaner to read, although my initial excitement of the function was somewhat abated given the usage limitations. I agree that a replace_batch would be great, although in fairness I have not had the need for it yet. Best wishes, Paul. PS The tables I have used it on had no primary key either. I have not experienced any real problems with that given the circumstances and use of the tables in question, although it did feel a bit strange at first not having one, and phpmyadmin doesn't allow inline editing of table content without one which was a bit of a pain during development. |
Welcome Guest, Not a member yet? Register Sign In |