• Start

Languages

/

PHP

/

v2 (alpha)

Installation

Install version 2 of the SurrealDB PHP SDK with Composer, including a PSR-18 HTTP client.

Version 2 of the PHP SDK is installed with Composer. It requires PHP 8.4 or later.

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.1

If you want Composer to keep tracking alpha releases, set the stability flag instead:

composer require "surrealdb/surrealdb.php:^2.0@alpha"

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

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;

Was this page helpful?