• Start

Languages

/

PHP

/

Libraries

/

Surqlize (ORM)

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 client does. You register that instance once during bootstrap, and Surqlize uses it for every model query.

Create and connect an SDK Surreal instance, then hand it to the ConnectionManager.

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.

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

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().

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

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

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

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

Was this page helpful?