Version 2 of the PHP SDK is installed with Composer. It requires PHP 8.4 or later.
Install the SDK
Version 2 is an alpha release, so you need to request the exact version. Composer will not select it under the default stable minimum stability.
composer require surrealdb/surrealdb.php:2.0.0-alpha.1If you want Composer to keep tracking alpha releases, set the stability flag instead:
composer require "surrealdb/surrealdb.php:^2.0@alpha"Add an HTTP client
The HTTP engine uses PSR-18 and PSR-17 interfaces rather than a built-in client. Install a compatible client and factory implementation, plus discovery so the SDK can find them automatically.
composer require guzzlehttp/guzzle php-http/discovery The WebSocket engine uses PHP's native stream functions and needs no extra packages. You only need a PSR-18 client when connecting over http:// or https://, or when using import and export.
Import the SDK
Include the Composer autoloader, then import the classes you need from the SurrealDB\SDK namespace.
require __DIR__ . '/vendor/autoload.php';
use SurrealDB\SDK\Surreal;
use SurrealDB\SDK\Connection\ConnectOptions;
use SurrealDB\SDK\Auth\RootAuth;
use SurrealDB\SDK\Types\RecordId;
use SurrealDB\SDK\Types\Table;Next steps
Getting started to connect and run your first queries
Connecting to SurrealDB for connection options and reconnection
Migration guide if you are coming from v1