CodeIgniter Forums
Database Seeder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Database Seeder (/showthread.php?tid=76125)



Database Seeder - illmaren - 04-15-2020

Is there a way to put multiple datasets into the $data variable described here?
https://codeigniter.com/user_guide/dbmgmt/seeds.html

I try to go with a multidimensional array but it tells me that there is a mysql error :$


RE: Database Seeder - InsiteFX - 04-15-2020

The $data can only be one level because it is defining the columns in the database table.


RE: Database Seeder - jribeirojr - 06-13-2020

you can do as follows to be able to insert multiple records

$data_category = [
array('category' => 'Test 01', 'ordination' => '1'),
array('category' => 'Test 02', 'ordination' => '2'),
array('category' => 'Test 03', 'ordination' => '3'),
array('category' => 'Test 04', 'ordination' => '4')
];

// Using Query Builder
$this->db->table('categories')->emptyTable();
$this->db->table('categories')->insertBatch($data_category);

Hope this helps