In this post i will show you how to insert multiple rows in CodeIgniter by using CI’s active records library. CI active record has a function insert_batch().By using this function we can insert multiple rows with single query and You can either pass an array or an object to the function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name' ,
'date' => 'My date'
),
array(
'title' => 'Another title' ,
'name' => 'Another Name' ,
'date' => 'Another date'
)
);
$this->db->insert_batch('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
|
I hope you like this Post, Please feel free to comment below, your suggestion.
No comments:
Post a Comment