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' => '[email protected]'
]);
Insert Multiple Records
$this->db->insert('some_table',
['name' => 'John Smith', 'email' => '[email protected]'],
['name' => 'Luke', 'email' => '[email protected]'],
['name' => 'Lisa', 'email' => '[email protected]']
);
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);