Version 2 is a rewrite of the PHP SDK. The namespace, the query API, the credential types, and the connection options all changed. This guide maps each v1 pattern to its v2 equivalent.
Important
What changed
The namespace moved from
Surreal\toSurrealDB\SDK\.Mutations use fluent builders that end in
execute(), instead of taking data as a second argument.Raw SurrealQL runs through
run(). In v1,query()ran SurrealQL; in v2,query()takes a pre-builtBoundQuery.Credentials are typed classes such as
RootAuth, andsignin()returns aTokensobject instead of a string.Connection settings are passed as a
ConnectOptionsobject, anduse()takes positional arguments.Data type classes moved to
SurrealDB\SDK\Typesand use named constructors such asRecordId::from().Import and export moved to
$db->connection().
1. Install version 2
Update your PHP version to 8.4 or later, then require the alpha release and a PSR-18 HTTP client.
2. Update the namespace
3. Update the connection
In v2, pass connection settings as a ConnectOptions object and select the namespace and database with positional arguments.
4. Update authentication
Credentials are now typed classes, and signin() returns a Tokens object.
Record access uses RecordAccessAuth, and the scope key is now access.
5. Update queries
Raw SurrealQL moves from query() to run(). Mutations become fluent builders.
6. Update data types
Data type classes moved to SurrealDB\SDK\Types and use named constructors.
The RecordId properties also changed: ->tb is now ->table.
7. Update import and export
Method mapping
| v1 | v2 |
|---|---|
new \Surreal\Surreal() | new \SurrealDB\SDK\Surreal() |
connect($url, ['namespace' => ..., 'database' => ...]) | connect($url, new ConnectOptions(namespace: ..., database: ...)) |
use(['namespace' => $ns, 'database' => $db]) | use($ns, $db) |
signin([...]): string | signin(new RootAuth(...)): Tokens |
query($sql, $vars) | run($sql, $vars) |
select($thing) | select($thing)->execute() |
create($thing, $data) | create($thing)->content($data)->execute() |
update($thing, $data) | update($thing)->content($data)->execute() |
merge($thing, $data) | update($thing)->merge($data)->execute() |
patch($thing, $patches) | update($thing)->patch($patches)->execute() |
insert($table, $data) | insert(new Table($table), $data)->execute() |
insertRelation($table, $data) | insert(new Table($table), $data)->relation()->execute() |
delete($thing) | delete($thing)->execute() |
relate($from, $edge, $to, $data) | relate($from, $edge, $to, $data)->execute() |
run('fn::foo', '1.0', $args) | call('fn::foo', '1.0', $args)->execute() |
RecordId::create('t', 'id') | RecordId::from('t', 'id') |
Table::create('t') | new Table('t') |
import($sql, $user, $pass) | connection()->importSql($sql) |
export($user, $pass) | connection()->exportSql() |
status(): int | status(): ConnectionStatus |
Removed and changed APIs
info()is not exposed on the v2Surrealclass. Use theauth()builder, which compiles toSELECT * FROM ONLY $auth.The SurrealML import and export helpers (
importML(),exportML()) are not part of the v2 public API.query()no longer runs raw SurrealQL. It executes aBoundQuery; userun()for raw statements.status()returns aConnectionStatusenum rather than an HTTP status integer.
Learn more
v2 overview for the new SDK
Executing queries for the builder API
Authentication for the credential types