Welcome Guest, Not a member yet? Register   Sign In
Just found $this->db->replace()
#1
Heart 

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.  Heart

Paul.
Reply
#2

(This post was last modified: 08-05-2015, 09:10 AM by josetrindade.)

(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:

$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.  Heart

Paul.

I use it a lot, too. But a replace_batch() would be even better.
Reply
Reply
#4

(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.
Reply
#5

(This post was last modified: 08-21-2015, 01:06 PM by PaulD.)

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB