surrealdb / surrealdb.php
Official SurrealDB PHP Driver
1.0.0-beta.2
2024-11-07 11:06 UTC
Requires
- php: >=8.2
- ext-curl: *
- brick/math: 0.12.1
- composer/semver: 3.4.3
- khill/php-duration: 1.1.0
- phrity/websocket: 3.2.0
- ramsey/uuid: 4.7.6
- welpie21/cbor.php: 1.0.1
Requires (Dev)
- nikic/php-parser: v4.19.1
- phpstan/extension-installer: 1.3.1
- phpstan/phpstan: 1.10.67
- phpstan/phpstan-beberlei-assert: 1.1.2
- phpunit/php-code-coverage: 10.1.14
- phpunit/phpunit: 10.5.19
- vimeo/psalm: 5.23.1
This package is auto-updated.
Last update: 2024-12-13 18:33:52 UTC
README
The official SurrealDB SDK for PHP.
surrealdb.php
The official SurrealDB SDK for PHP.
Documentation
View the SDK documentation here.
How to install
You install the SurrealDB SDK via Composer. If you don't have Composer installed, you can download it here.
composer require surrealdb/surrealdb.php
Getting started
To get started, you need to create a new instance of the SurrealDB HTTP or WebSocket Class.
// Make a new instance of the SurrealDB class. Use the ws or wss protocol for having WebSocket functionality. $db = new \Surreal\Surreal(); $db->connect("http://localhost:8000", [ "namespace" => "test", "database" => "test" ]);
Basic Querying
In the PHP SDK, We have a simple API that allows you to interact with SurrealDB. The following example shows how to interact with the database.
The example below requires SurrealDB to be installed and running on port 8000.
// Connect set the specified namespace and database. $db = new \Surreal\Surreal(); $db->connect("http://localhost:8000", [ "namespace" => "test", "database" => "test" ]); // We want to authenticate as a root user. $token = $db->signin([ "user" => "root", "pass" => "root" ]); // Create a new person in the database with a custom id. $person = $db->create("person", [ "title" => "Founder & CEO", "name" => [ "first" => "Tobie", "last" => "Morgan Hitchcock" ], "marketing" => true ]); // Get the person with the name "John Doe". $record = \Surreal\Cbor\Types\Record\RecordId::create("person", "john"); $person = $db->select($record); // Update a person record with a specific id $record = \Surreal\Cbor\Types\Record\RecordId::create("person", "john"); $person = $db->merge($record, ["age" => 31]); // Select all people records. $people = $db->select("person"); // Perform a custom advanced query. $groups = $db->query('SELECT marketing, count() FROM $tb GROUP BY marketing', [ "tb" => \Surreal\Cbor\Types\Table::create("person") ]); // Close the connection between the application and the database. $db->close();
Contributing
Requirements
- PHP 8.1 or higher
- Composer
- SurrealDB 1.4.0 or higher
Run tests
./vendor/bin/phpunit -c phpunit.xml
Directory Structure
src
- The source code of the librarytests
- The unit tests of the library