Skip to content

Getting started

jadell edited this page Nov 18, 2011 · 23 revisions

Installation

The following assumes that Neo4j has already been installed and is accessible via http://localhost:7474/webadmin/# (or your specific hostname)

Quick Setup

  • Download neo4jphp.phar
  • Move the downloaded file to your include path
  • Include in your application:
include("neo4jphp.phar");

From Source

Get Neo4jPHP via git checkout git://github.com/jadell/Neo4jPHP.git or download the latest tagged release from https://github.com/jadell/Neo4jPHP/archives/master

Change into the Neo4jPHP directory

cd Neo4jPHP

With Phing

  • Build the package
phing test
phing package
  • Move the downloaded file to your include path
  • Include in your application: include("neo4jphp.phar");

Without Phing

If PHPUnit is installed, run tests

./tests/runtests

Verify that Neo4jPHP can talk to the Neo4j server

cd ./examples  
./bacon.php init  
./bacon.php "Keanu Reeves" "Kevin Bacon"  

You should see output indicating a path has been found between the two actors.

Neo4jPHP will need to be put where your application's autoloader can find it.

How this is done depends on how your application is structured, and which framework (if any) you are using. In general, symlink or copy the lib/Everyman directory into your application's autoload path, and set up the autoloader to look for any class in the Everyman namespace under this path. An example of how to do this for CodeIgniter 2 can be found at http://blog.everymansoftware.com/2011/08/getting-neo4jphp-working-with.html

Testing Your Connection

You can use the neo4jphp.phar archive to test your connection to a Neo4j instance from the command line:

> php neo4j.phar localhost

Change "localhost" to the host name of your Neo4j instance. If the connection is successful, you will see instance information output.

Creating a Connection to Neo4j

Neo4jPHP uses a Client object to encapsulate all communication with the server. This client is used in the construction of many of Neo4jPHP's other objects (nodes, relationships, etc.) The following code creates a Client:

// The host and port parameters are optional, and default to "localhost" and "7474"
$transport = new Everyman\Neo4j\Transport("localhost", 7474);
$client = new Everyman\Neo4j\Client($transport);

Create a node and persist it to the server:

$first_node = new Everyman\Neo4j\Node($client);
try {
    $first_node->save();
    echo "Node saved successfully!\n";
} catch (Everyman\Neo4j\Exception $e) {
    echo "Something went wrong!\n";
}

If saving the node worked, the node count at http://localhost:7474/webadmin/# will have incremented.

Congratulations! Neo4jPHP is set up and ready to use in your application.

Clone this wiki locally