database seeding in codeigniter4 code example
Example 1: codeigniter 4 db seed
> php spark db:seed TestSeeder
Example 2: codeigniter 4 db seed
<?php namespace App\Database\Seeds;
class SimpleSeeder extends \CodeIgniter\Database\Seeder
{
public function run()
{
$data = [
'username' => 'darth',
'email' => '[email protected]'
];
// Simple Queries
$this->db->query("INSERT INTO users (username, email) VALUES(:username:, :email:)",
$data
);
// Using Query Builder
$this->db->table('users')->insert($data);
}
}