Db::insert

Usage

void Db::insert(string $table_name, [ ... $args ])

Description

Insert new record(s) into a database table.

Parameters

Parameter Required Type Description
$table_name Yes string The table name to insert new record into.
$args No desc=

Examples

Insert Single Record


$this->db->insert('some_type', [ 'name' => 'John Smith', 'email' => 'john@domain.com' ]);

Insert Multiple Records


$this->db->insert('some_table', ['name' => 'John Smith', 'email' => 'john@domain.com'], ['name' => 'Luke', 'email' => 'luke@test.com'], ['name' => 'Lisa', 'email' => 'list@somewhere.com'] );

Insert Object


use App\Demo\Models\Product; // Create product $product = new Product( category_id: 13, price: 49.95, name: 'Test Product' ]); // Insert object $this->db->insert('products', $product);

See Also