Problem ArangoDB connection with PHP vendor

51 Views Asked by At

I would like to establish a database connection to ArangoDB with PHP. Vendor is installed, I have created an isolated script to just try the connection, but I always receive the following error message:

Uncaught Error: Class "ArangoDB\Connection" not found

This is my script (seems ok), so what could it be?

<?php
require 'vendor/autoload.php';

use ArangoDB\Connection;
use ArangoDB\Statement;
use ArangoDB\Cursor;

// Verbindung zur Datenbank auf einem anderen Server herstellen
$adb = new Connection([
    'name'       => 'arangodb',
    'driver'     => 'arangodb',
    'endpoint' => 'localhost',
    'database' => 'database',
    'username' => 'root',
    'password' => 'passwort',
]);

$query = new Statement($adb, [
    'query' => 'FOR doc IN your_collection RETURN doc',
]);

$cursor = new Cursor($query->execute());

foreach ($cursor as $document) {
    // Verarbeite das Dokument hier
}

?>

I have tried variations, like absolute https-path to the db, name and driver came later, also ChatGPT could not help me.

It seems that the connection class is not found (as said in the error message). But I don't have the minor idea why, as the vendor is installed and should deliver the classes.

Anyone has an idea? THANK YOU!

EDIT: This seems the rights config:

<?php
require 'vendor/autoload.php'; // Pfadeinstellung zur Composer-Autoloader-Datei

use ArangoDBClient\ConnectionOptions;
use ArangoDBClient\Connection as ArangoConnection;

// Verbindungsoptionen festlegen
$connectionOptions = [
    // Datenbank-URL angeben
    ConnectionOptions::OPTION_ENDPOINT => 'tcp://localhost:8529',
    // Benutzername und Passwort angeben
    ConnectionOptions::OPTION_AUTH_USER => 'username',
    ConnectionOptions::OPTION_AUTH_PASSWD => 'password',
    // Datenbanknamen angeben
    ConnectionOptions::OPTION_DATABASE => 'mydatabase',
    // Optionale Einstellungen
    ConnectionOptions::OPTION_TIMEOUT => 30,
    ConnectionOptions::OPTION_CONNECTION => 'Keep-Alive',
    ConnectionOptions::OPTION_RECONNECT => true,
];

// Verbindung zur ArangoDB-Datenbank herstellen
$connection = new ArangoConnection($connectionOptions);
?>
0

There are 0 best solutions below