Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/surrealdb/surrealdb.php
SurrealDB SDK for PHP
https://github.com/surrealdb/surrealdb.php
Last synced: 3 months ago
JSON representation
SurrealDB SDK for PHP
- Host: GitHub
- URL: https://github.com/surrealdb/surrealdb.php
- Owner: surrealdb
- License: apache-2.0
- Created: 2022-09-02T10:50:07.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-20T20:50:48.000Z (4 months ago)
- Last Synced: 2024-07-27T23:32:27.666Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 98.6 KB
- Stars: 36
- Watchers: 20
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-surreal - surrealdb.php - <a href="https://surrealdb.com#gh-dark-mode-only" target="_blank"><img src="/img/white/text.svg" height="12" alt="SurrealDB"></a> <a href="https://surrealdb.com#gh-light-mode-only" target="_blank"><img src="/img/black/text.svg" height="12" alt="SurrealDB"></a> official driver for PHP. (Client libraries)
README
The official SurrealDB SDK for PHP.
# surrealdb.php
The official SurrealDB SDK for PHP.
## Documentation
View the SDK documentation [here](https://surrealdb.com/docs/integration/libraries/php).
## How to install
You install the SurrealDB SDK via [Composer](https://getcomposer.org/). If you don't have Composer installed, you can download it [here](https://getcomposer.org/download/).
```sh
composer require surrealdb/surrealdb.php
```## Getting started
To get started, you need to create a new instance of the SurrealDB HTTP or WebSocket Class.
```php
// 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](https://surrealdb.com/install) and running on port 8000.
```php
// 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\RecordId::create("person", "john");
$person = $db->select($record);// Update a person record with a specific id
$record = \Surreal\Cbor\Types\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->disconnect();
```## Contributing
### Requirements
- PHP 8.1 or higher
- Composer
- SurrealDB 1.4.0 or higher### Run tests
```bash
./vendor/bin/phpunit -c phpunit.xml
```### Directory Structure
- `src` - The source code of the library
- `tests` - The unit tests of the library