-
Notifications
You must be signed in to change notification settings - Fork 46
Home
Welcome to the ArangoDB-PHP wiki!
- Read this first
- Description
- Installing the PHP client
- Using packagist/composer
- Cloning the git repository
- How to use the PHP client
- Supported PHP versions
- Changelogs
<a name="read_this_first"/a>
Important versioning information on ArangoDB-PHP
Have a question about ArangoDB-PHP? Check for already answered ArangoDB-PHP questions at Stackoverflow or ask your own.
BTW: You can also check ArangoDB generic questions at Stackoverflow or ask your own.
Check the Supported PHP versions and the Changelogs
Follow us on Twitter @arangodbphp to receive updates on the php driver
<a name="description"/a>
This PHP client allows REST-based access to documents on the server. The ArangoDocumentHandler class should be used for these purposes. There is an example for REST-based documents access in the file examples/document.php.
Furthermore, the PHP client also allows to issue more complex queries using the ArangoStatement class. There is an example for this kind of statements in the file examples/select.php.
To use the PHP client, you must include the file autoloader.php from the main directory. The autoloader will care about loading additionally required classes on the fly. The autoloader can be nested with other autoloaders.
The ArangoDB PHP client is an API that allows you to send and retrieve documents from ArangoDB from out of your PHP application. The client library itself is written in PHP and has no further dependencies but just plain PHP 5.3 (or higher).
The client library provides document and collection classes you can use to work with documents and collections in an OO fashion. When exchanging document data with the server, the library internally will use the HTTP REST interface of ArangoDB. The library user does not have to care about this fact as all the details of the REST interface are abstracted by the client library.
<a name="installing"/a>
To get started you need PHP 5.3 or higher plus an ArangoDB server running on any host that you can access.
There are two alternative ways to get the ArangoDB PHP client:
- Using packagist/composer
- Cloning the git repository
<a name="using_packagist"/a>
When using packagist, the procedure is as follows:
Get the composer.phar file from getcomposer.org:
curl -s http://getcomposer.org/installer | php
This will put the composer.phar file into the current directory. Next, create a new directory for your project, e.g. arangophp, and move into it:
mkdir arangophp && cd arangophp
Then, use composer's init command to define the initial dependencies for your project:
php ../composer.phar init
This will fire up composer's interactive config generator. It will ask you several questions, and the below example shows how you can answer them. Most questions have reasonable default settings and you can should use the defaults whenever you're unsure. When asked for a package name, type ## triagens/arangodb. This is the package name for the ArangoDB PHP client. When being asked for a package number (package ##), you can either use dev-master (latest version) or one of the designated tagged versions.
Welcome to the Composer config generator
This command will guide you through creating your composer.json config.
Package name (/) [jsteemann/arangophp]:
Description []: An example application using ArangoDB PHP client
Author [jsteemann]:
Define your dependencies.
Would you like to define your dependencies interactively [yes]? yes
Search for a package []: triagens/arangodb
Found 3 packages matching triagens/arangodb
[0] triagens/arangodb dev-master
[1] triagens/arangodb V0.1.1
[2] triagens/arangodb V0.0.1
Enter package ## to add, or a couple if it is not listed []: 0
Search for a package []:
{
"name": "jsteemann/arangophp",
"description": "An example application using ArangoDB PHP client",
"require": {
"triagens/arangodb": "dev-master"
},
"authors": [
{
"name": "jsteemann",
"email": "[email protected]"
}
]
}
Do you confirm generation [yes]? yes
Would you like the vendor directory added to your .gitignore [yes]?
The above has created a file composer.json in your current directory, which contains information about your project plus the project dependencies. The ArangoDB PHP client is the only dependency for now, and it can be installed by running the following command:
php ../composer.phar update
Updating dependencies
- Package triagens/arangodb (dev-master)
Cloning e4e9107aec3d1e0c914e40436f77fed0e5df2485
Writing lock file
Generating autoload files
Running this command has created a subdirectory vendor in the current directory. The vendor directory contains a subdirectory triagens that contains the ArangoDB PHP client library files. The vendor directory also contains a subdirectory .composer that contains auto-generated autoloader files for all dependencies you defined in your composer.json file (the file auto-generated by running the previous init command).
You need to include the generated autoloader file in your project when using the ArangoDB PHP classes. You can do so by adding the following line to any PHP file that will use them:
require 'vendor/.composer/autoload.php';
<a name="cloning_git"/a>
When preferring this alternative, you need to have a git client installed. To clone the ArangoDB PHP client repository from github, execute the following command in your project directory:
git clone "https://github.com/arangodb/arangodb-php.git"
This will create a subdirectory arangodb-php
in your current directory. It contains all the files of the client library. It also includes a dedicated autoloader that you can use for autoloading the client libraries class files.
To invoke this autoloader, add the following line to your PHP files that will use the library:
require 'arangodb-php/autoload.php';
The ArangoDB PHP client's autoloader will only care about its own class files and will not handle any other files. That means it is fully nestable with other autoloaders.
<a name="supported_php_version"/a>
The client is tested on Travis-CI and runs happily on PHP and HHVM. Please refer to the Compatibility Matrix below for specific version support.
ArangoDB-PHP Version | PHP Version |
---|---|
3.0.x | PHP >= 5.4, HHVM |
3.1.x | PHP >= 5.5, HHVM |