Skip to content

TeddyBear06/edgedb-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unofficial EdgeDB HTTP PHP client

Requirements

  • PHP >= 8.0 (with fileinfo and mbstring)
  • An EdgeDB server instance (tested with 2.0.5+f78cf34)

Quickstart

Add this package to your project:

$ composer require teddybear06/edgedb-php

This is a complete usage example (or look at https://github.com/TeddyBear06/edgedb-php/tree/main/example/index.php):

// Require Composer's autoloader 
require '/vendor/autoload.php';

// Use required classes
use TeddyBear06\EdgeDbPhp\EdgeDbHttpClient;
use TeddyBear06\EdgeDbPhp\EdgeQlQuery;

// Establish a connection with the EdgeDB server instance
$connection = new EdgeDbHttpClient('127.0.0.1', '10700', 'edgedb');

// Create an EdgeQL query
$query = new EdgeQlQuery(
    'select Author {firstname, lastname} filter .lastname = <str>$lastname;', 
    ['lastname' => 'Doe']
);

// Execute the query
$response = $connection->query($query);

// If there is no error message
if (is_null($response->getError())) {

    // If there is at least 1 result
    if ($response->countData() > 0) {

        // Loop over results
        foreach ($response->getData() as $data) {
            echo $data['firstname'];
        }

    } else {

        // Data set is empty
        echo 'No matches found...';

    }

} else {

    // Call $response->getError() to get error details
    // message, type or code array indexes are available
    echo $response->getError()['message'];

}

Documentation

For a complete API documentation, please go here : https://teddybear06.github.io/edgedb-php/