codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

Added insert_batch to use with the mapped table in the model

Open upcesar opened this issue 10 years ago • 1 comments
trafficstars

Hello, this CI Extension Class helped me a lot for encapsulating some native plumbing db model methods. When I searched for a "insert_batch()" method in this extended class (for further info: https://ellislab.com/codeigniter/user-guide/database/active_record.html#insert) , I didn't found it and I didn't want to use the native CI method, because I had to pass 2 parameters, just like this:

$this->db->insert_batch(string $table_name, array $data);

Searching I've found the method insert_many(), but it also loops to add one by one. That why I created this method in the extension class, since it's faster adding records in batch, saving time and requests with DB Server.

With this new merthod, you anyone can use it like this, since it uses default table name:

$this->my_model->insert_batch(array $data);

Keep in mind the data must be validated before passing to this method.

upcesar avatar Jul 02 '15 20:07 upcesar

@upcesar , use $this->_database instate of $this->db

michail1982 avatar Jul 02 '15 20:07 michail1982