# Connections

Register an SDK executor with Surqlize's ConnectionManager, and inject a per-query executor when you need more than one connection.

Surqlize does not open its own connection. It runs queries through an SDK instance that implements the SDK's `QueryExecutor` contract, which the [`Surreal`](/docs/reference/php/v2/api/core.md) client does. You register that instance once during bootstrap, and Surqlize uses it for every model query.

## Registering the executor

Create and connect an SDK [`Surreal`](/docs/reference/php/v2.md) instance, then hand it to the `ConnectionManager`.

```php
use Surqlize\Connection\ConnectionManager;
use SurrealDB\SDK\Surreal;
use SurrealDB\SDK\Connection\ConnectOptions;
use SurrealDB\SDK\Auth\RootAuth;

$db = new Surreal();
$db->connect('ws://127.0.0.1:8000/rpc', new ConnectOptions(
    namespace: 'surrealdb',
    database: 'docs',
    authentication: new RootAuth('root', 'root'),
));

ConnectionManager::set($db);
```

Once set, model queries resolve the executor automatically.

```php
$users = User::query()->collectModels();
```

## Per-query executors

`ConnectionManager` is a global singleton. When you need to run against a different connection, or want to avoid the singleton entirely, inject an executor for a single query with `withExecutor()`.

```php
$users = User::query()
    ->withExecutor($otherDb)
    ->collectModels();
```

The model helper methods accept an executor through an `executor:` argument for the same purpose.

```php
$user = User::create(['name' => 'Tobie', 'age' => 32], id: 'tobie', executor: $otherDb);

$user = User::find('tobie', executor: $otherDb);
```

> [!NOTE]
> In a [Laravel application](/docs/reference/php/frameworks/laravel.md), the integration registers the executor for you, so you do not call `ConnectionManager::set()` yourself.

## Learn more

- [PHP SDK v2](/docs/reference/php/v2.md) for connecting the underlying client
- [Querying](/docs/reference/php/libraries/surqlize/querying.md) for running queries through the executor
- [Transactions](/docs/reference/php/libraries/surqlize/transactions.md) for batching queries atomically
