How to insert multiple array data using codeigniter active record

Below is the example to insert multiple array data using query builder class of codeigniter. By using $this->db->insert_batch() method we can achieve this.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class InsertController extends CI_Controller {
public function __construct()
{
parent::__construct();
}
    public function index() {
        $data[] = array(
'name'=>'Avinash',
'mobile'=>'72345613',
'address'=>'Delhi'
);
$data[] = array(
'name'=>'Dinesh',
'mobile'=>'78945676',
'address'=>'Mumbai'
);
$this->db->insert_batch( 'tbl_user', $data );
    }
}
Thank you for reading this post. we hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – let us know. We’d love to help!

I am Hitesh from Jamshedpur (India). I have been working as a Web Application Developer from last 4+ years. I love diverse and attention catching web presence for a variety of users. Also I love to learn new things in Web Development.

Tags: ,