amy burgess
amy burgess

Reputation: 115

Codeigniter batch update performance

Does $this->db->update_batch(); update with 1 table connection or does it update each row separately incurring overhead of opening connections?

I'm wondering if this is faster than using foreach and $this->db->update();

Upvotes: 1

Views: 666

Answers (1)

Rejoanul Alam
Rejoanul Alam

Reputation: 5398

As in Codeigniter documentation $this->db->update_batch(); generate a single query and establish only one connection. So it would be faster than query within foreach loop.

After profiling I can see following results (only 0.0700 sec taken to update 4 rows)

UPDATE batch

on other hand I have updated same no. of rows with loop and it takes much time (0.665 sec which is almost 1 sec)

foreach loop

Upvotes: 4

Related Questions