In this tutorial, we will learn how to insert multiple records into a MySQL table using CI's active records library. Sometime, We may require to insert multiple rows instead of single records. It also takes a few time and adds multiple rows in a database table.
Codeigniter 3 have an active records library and they provide insert_batch() to create multiple records at a time. So I also added a small example, so you can see that and learn how it can be possible.
Insert Multiple Records:
$insertArray = [
[
'name' => 'My Name',
'detail' => 'My Detail'
],
[
'name' => 'My Name',
'detail' => 'My Detail'
]
];
$this->db->insert_batch('mytable_name', $insertArray);
As you can see above syntax example and understand how it works and easy to use.
So, just do that way.
I hope you found your best.
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?