![]() |
Just found $this->db->replace() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1) +--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3) +--- Thread: Just found $this->db->replace() (/showthread.php?tid=62525) |
Just found $this->db->replace() - PaulD - 07-24-2015 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. RE: Just found $this->db->replace() - josetrindade - 08-05-2015 (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. RE: Just found $this->db->replace() - ivantcholakov - 08-05-2015 http://code.openark.org/blog/mysql/replace-into-think-twice RE: Just found $this->db->replace() - josetrindade - 08-05-2015 (08-05-2015, 10:22 AM)ivantcholakov Wrote: http://code.openark.org/blog/mysql/replace-into-think-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. RE: Just found $this->db->replace() - PaulD - 08-21-2015 (08-05-2015, 10:22 AM)ivantcholakov Wrote: http://code.openark.org/blog/mysql/replace-into-think-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. |