---
title: "Session: Storing Entities"
url: "https://docs.ravendb.net/6.2/client-api/session/storing-entities"
version: "6.2"
language: "php"
---

# Session: Storing Entities

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/storing-entities.md), [Java](https://docs.ravendb.net/6.2/client-api/session/storing-entities.java.md), [Python](https://docs.ravendb.net/6.2/client-api/session/storing-entities.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/storing-entities.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

To store entities inside the **session** object, use one of the three `store` methods.

## Syntax

First overload: Stores the entity in a session, then extracts the ID from the entity or generates a new one if it's not available.

```php
public function store(?object $entity): void;
```

Second overload: Stores the entity in a session with given ID.

```php
public function store(?object $entity, ?string $id): void;
```

Third overload: Stores the entity in a session with given ID, forces concurrency check with given change vector.

```php
public function store(?object $entity, ?string $id, ?string $changeVector): void;
```

| Parameters | | |
| - | - | - |
| **entity** | `object` | Entity that will be stored |
| **changeVector** | `string` | Entity changeVector, used for concurrency checks (`null` to skip check) |
| **id** | `string` | Entity will be stored under this ID, (`null` to generate automatically) |

## Example

```php
$employee = new Employee();
$employee->setFirstName("John");
$employee->setLastName("Doe");

// generate Id automatically
$session->store($employee);

// send all pending operations to server, in this case only `Put` operation
$session->saveChanges();
```

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.php.md)
- [Opening a Session](https://docs.ravendb.net/6.2/client-api/session/opening-a-session.php.md)
- [Loading Entities](https://docs.ravendb.net/6.2/client-api/session/loading-entities.php.md)
- [Saving Changes](https://docs.ravendb.net/6.2/client-api/session/saving-changes.php.md)
- [Query Overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.php.md)
- [Basics](https://docs.ravendb.net/6.2/indexes/querying/query-index.php.md)
- [What is a Document Store](https://docs.ravendb.net/6.2/client-api/what-is-a-document-store.md)
