Low level PHP client for ArangoDB. Supports PHP ^8.0.
This client is a conduit to ArangoDB and back, so it doesn't make any presumptions on the returned data itself. JSON objects are decoded to POPO's. You can cast those to what you need in your ODM or project.
composer require laravel-freelancer-nl/arangodb-php-client
$client = new ArangoClient($config);
Use the schemaManager to create a new collection.
$client->schema()->createCollection('users');
$statement = $client->prepare('FOR user in Users RETURN user');
$statement->execute();
$users = $statement->fetchAll();
As there are no users yet in the above example this will yield an empty result. Note that this client does not have any preconceptions about the data structure and thus everything is returned as raw arrays.
The connector has a default configuration for a local ArangoDB instance at it's default port (8529).
To run AQL queries you prepare a query, execute it and fetch the results. Much like PHP's PDO extension.
$statement = $client->prepare('FOR user in users RETURN user');
$statement->execute();
$users = $statement->fetchAll();
Alternatively you can traverse over the statement itself to get the results one at a time.
$statement = $client->prepare('FOR user in users RETURN user');
$statement->execute();
foreach ($statement as $document) {
//
}
You have access to several managers that allow you to perform specific tasks on your ArangoDB instance(s). Their functions can be called on the manager.
The admin manager manages administrative functions and information retrieval for the server/cluster.
$client->admin()->version();
The monitor manager manages monitoring functions the server/cluster.
$client->monitor()->getMetrics();
The schema manager manages all schema related operations.
$client->schema()->createDatabase('new_db');
The transaction manager takes care of all transactions.
$client->transactions()->begin(['write' => ['users', 'teams']]);