在codeigniter中批量删除

insert_batch() is a codeigniter build-in function which inserts 100 data of rows at a time. That's why it is so much faster for inserting large amount of data.

Now I want to delete large number of data like insert_batch() function does.

Is their any way to do it?

Already I am using where_in function but it is not that much faster like insert_batch() and that's why timeout error occur often.

I want to know specially that can i make a function like insert_batch() or insert_update() in codeigniter system/database/db_query_builder ?

If I can how to do it. or any other suggestion please ?

If we are talking about alot of rows, it may be easier to perform a table 'switch' by inserting and dropping the the original table.

However one drawback to this will mean any Auto Increment IDs will be lost.

<?php

// Create a Copy of the Same Data structure
$this->db->query( "CREATE TABLE IF NOT EXISTS `TB_TMP` .. " );

// Select the data you wish to -Keep- by excluding the rows by some condition.
// E.g. Something that is no longer active.
$recordsToKeep = 
    $this->db
         ->select( "*" )
         ->get_where( "TB_LIVETABLE", [ "ACTIVE" => 1 ])
         ->result();

// Insert the Excluded Rows.
$this->db->insert_batch( "TB_TMP", $recordsToKeep );

// Perform the Switch
$this->db->query( "RENAME TABLE TB_LIVETABLE TO TB_OLDTABLE" );
$this->db->query( "RENAME TABLE TB_TMP TO TB_LIVETABLE " );
$this->db->query( "DROP TABLE TB_OLDTABLE" );