• Start

v1 (stable)

/

Methods

insert

Insert one or multiple records in the database using the insert method with the SurrealDB PHP SDK.

Inserts one or multiple records in the database.

Method Syntax
$db->insert($thing, $data)

Arguments

Type

Description

thingstring

The table name or RecordId to insert to.

dataassociative array

Either a single document/record or an array of documents/records to insert

// Insert a single record
[$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,
	],
]);

// Insert multiple records
$people = $db->insert('person', [
	[
		"name" => 'Tobie',
		"settings" => [
			"active" => true,
			"marketing" => true,
		],
	],
	[
		"name" => 'Jaime',
		"settings" => [
			"active" => true,
			"marketing" => true,
		],
	],
]);

// The content you are creating the record with might differ from the return type
$people = $db->insert('person', [
	[ "name" => 'Tobie' ],
	[ "name" => 'Jaime' ],
]);

This function will run the following query in the database.

INSERT INTO $thing $data;

Was this page helpful?