# upsert

The upsert method in the SurrealDB PHP SDK allows you to create or update a record in a table.

Creates or updates a record in a table.

```php title="Method Syntax"
$db->upsert($thing, $data);
```

## Arguments

<table>
	<thead>
		<tr>
			<th colspan="2" scope="col">Arguments</th>
			<th colspan="2" scope="col">Type</th>
			<th colspan="2" scope="col">Description</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td colspan="2" scope="row" data-label="Arguments">
				<code>$thing</code>
				<label label="required" />
			</td>
			<td colspan="2" scope="row" data-label="Type">
				`RecordId`. `StringRecordId` or `string`
			</td>
			<td colspan="2" scope="row" data-label="Description">
				The collection to upsert the record to.
			</td>
		</tr>
		<tr>
			<td colspan="2" scope="row" data-label="Arguments">
				<code>$data</code>
				<label label="required" />
			</td>
			<td colspan="2" scope="row" data-label="Type">
				`mixed`
			</td>
			<td colspan="2" scope="row" data-label="Description">
				The record to upsert.
			</td>
		</tr>
	</tbody>
</table>

## Example

```php title="Example"
$id = new RecordId('users', 'tobie');

// Upsert a record to the "users" collection.
$response = $db->upsert($id, [
	'firstname' => 'Tobie',
	'lastname' => 'Hitchcock',
]);
```
