->insert()
Inserts one or multiple records in the database.
Method Syntax
$db->insert($thing, $data)
Arguments
| Arguments | Type | Description |
|---|
thing required | string | The table name or RecordId to insert to. |
data optional | associative array | Either a single document/record or an array of documents/records to insert |
Example usage
[$person] = $db->insert('person', [
"name" => 'Tobie',
"settings" => [
"active" => true,
"marketing" => true,
],
]);
$person = $db->insert(new RecordId('person', 'tobie'), [
"name" => 'Tobie',
"settings" => [
"active" => true,
"marketing" => true,
],
]);
$people = $db->insert('person', [
[
"name" => 'Tobie',
"settings" => [
"active" => true,
"marketing" => true,
],
],
[
"name" => 'Jaime',
"settings" => [
"active" => true,
"marketing" => true,
],
],
]);
$people = $db->insert('person', [
[ "name" => 'Tobie' ],
[ "name" => 'Jaime' ],
]);
Translated query
This function will run the following query in the database.
INSERT INTO $thing $data;