• Start

Languages

/

PHP

/

Methods

create

Create a record in the database using the create method with the SurrealDB PHP SDK.

Creates a record in the database.

Method Syntax

$db->create($thing, $data)
ArgumentsTypeDescription
thing string, RecordId or StringRecordId The table name or a RecordId to create.
data mixed The document / record data to create.
// Create a record with a random ID
[$person] = $db->create('person');

// Create a record with a specific ID
$person = $db->create(new RecordId('person', 'tobie'), [
"name" => 'Tobie',
"settings" => [
"active" => true,
"marketing" => true,
],
]);

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

This function will run the following query in the database.

CREATE $thing CONTENT $data;

Was this page helpful?