Codeigniter update batch where

Blog

Why you need to use the bulk insert, update, and delete in Codeigniter….? there are many reasons; the one reason is you are fetching the id of a table and inserting that id in a new table.

If you call insert query in the loop, yes, you can do that, but it can decrease your system performance, so how can you insert the values ​​..? Codeigniter proving the bulk adding functionality using query builder, you need to call the method in your model

Imagine if you have millions of records inside your loop that means you are calling millions of time the insert query; This is not a good practice if you are working on the MVC Framework.

Here is the simple solution to your problem; As you can see below, you are inserting many records using a single query, so it depends on how you are coding in your project.

There are many ways where you can use the batch insert and update it. CodeIgniter for supposing you are creating the blog system where you have a relational database like blogs table and the tags table, in the tags table you are sending the blog’s id as a foreign key in the tags table.

You can send the tags ’data in the array from HTML and now break the operation to insert your blog.

Step 1: insert the blog content in the blogs table and get the currently added id of the table and send it to the tags table to enter the tag’s elements below the example code.

Here is the model’s method. We are inserting the blog content and fetching the currently added id.

Now we can fetch the tag’s data, which is coming from the HTML

If you want to update the bulk records in CodeIgniter its very simple just use the update_batch fromquery builder

So now ho can you delete your multiple records with a single query Its very simple just use the where_in method inquery builder.

You Might Also Like