SurrealDB has types that PHP does not, such as record IDs, nanosecond datetimes, durations, and arbitrary-precision decimals. Version 2 of the SDK represents these with value classes in the SurrealDB\SDK\Types namespace. Native PHP types pass through unchanged.
Type mapping
| SurrealQL type | PHP type |
|---|---|
bool | bool |
int, float | int, float |
string | string |
null | null |
none | None |
array | array (list) |
object | array (associative) |
set | Set |
bytes | Bytes |
datetime | DateTime |
duration | Duration |
decimal | Decimal |
uuid | Uuid |
record | RecordId |
range | Range |
geometry | Geometry types |
file | File |
Record IDs and tables
A RecordId is a table name plus an ID. A Table is a table reference on its own. The query builders accept either, so the SDK can tell a record from a table.
The ID can be a string, integer, array, or object for composite keys.
To send a record ID that is already a string, wrap it in StringRecordId so the server parses it.
Datetimes and durations
A DateTime keeps nanosecond precision, which PHP's native DateTime does not. A Duration follows SurrealQL duration syntax.
Decimals
A Decimal holds a number without floating-point rounding. Construct it from a string when precision matters.
UUIDs
A Uuid represents a universally unique identifier, with helpers for v4 (random) and v7 (time-ordered).
Geometries
The SDK provides classes for every GeoJSON geometry type: GeometryPoint, GeometryLine, GeometryPolygon, GeometryMultiPoint, GeometryMultiLine, GeometryMultiPolygon, and GeometryCollection.
Learn more
Data types API reference for every value class and its methods
SurrealQL data model for the database type system