World's leading graph database, with native graph storage and processing.

Property graph model and Cypher query language makes it easy to understand.

Fast. Natural. Fun.

Test-Drive Neo4j with Cypher

Friends of Friends

Find all of Joe's second-degree friends


Joe knows Sally, and Sally knows Anna. Bob is excluded from the result because, in addition to being a 2nd-degree friend through Sally, he's also a first-degree friend.

 * To install Neo4j-PHP-Client, we use Composer
 * $ curl -sS https://getcomposer.org/installer | php
 * $ php composer.phar require graphaware/neo4j-php-client

require __DIR__.'/vendor/autoload.php';

use GraphAware\Neo4j\Client\ClientBuilder;

// change to your hostname, port, username, password
$neo4j_url = "bolt://neo4j:password@localhost";

// setup connection
$client = ClientBuilder::create()
    ->addConnection('default', $neo4j_url)

// setup data
$insert_query = <<<EOQ
UNWIND {pairs} as pair
MERGE (p1:Person {name:pair[0]})
MERGE (p2:Person {name:pair[1]})
MERGE (p1)-[:KNOWS]-(p2);

// friend data to insert
$data = [["Jim","Mike"],["Jim","Billy"],["Anna","Jim"],

// insert data
$client->run($insert_query, ["pairs" => $data]);

// friend of friend: query
$foaf_query = <<<EOQ
MATCH (person:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf)
WHERE person.name = {name}
  AND NOT (person)-[:KNOWS]-(foaf)
RETURN foaf.name AS name

// friend of friend: build and execute query
$params = ['name' => 'Joe'];
$result = $client->run($foaf_query, $params);

foreach ($result->records() as $record) {
  echo $record->get('name') . PHP_EOL;

// common friends: query
$common_friends_query = <<<EOQ
MATCH (user:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf:Person)
WHERE user.name = {user} AND foaf.name = {foaf}
RETURN friend.name AS friend

// common friends: build and execute query
$params = ['user' => 'Joe', 'foaf' => 'Sally'];
$result = $client->run($common_friends_query, $params);

foreach ($result->records() as $record) {
  echo $record->get('friend') . PHP_EOL;

// connecting paths: query
$connecting_paths_query = <<<EOQ
MATCH path = shortestPath((p1:Person)-[:KNOWS*..6]-(p2:Person))
WHERE p1.name = {name1} AND p2.name = {name2}
RETURN [n IN nodes(path) | n.name] as names

// connecting paths: build and execute query
$params = ['name1' => 'Joe', 'name2' => 'Billy'];
$result = $client->run($connecting_paths_query, $params);

foreach ($result->records() as $record) {

Downloading and Installing PHP

  1. Install Composer from within web directory: $ curl -sS https://getcomposer.org/installer | php
  2. Install Neo4j-PHP-Client from within web directory: $ php composer.phar require graphaware/neo4j-php-client
  3. Copy and paste code at left into php file and run

Intro to Graph Databases

  • Intro to Graph Databases Episode #1 - Evolution of DBs
  • Intro to Graph Databases Episode #2 - Properties of Graph DBs & Use Cases
  • Intro to Graph Databases Episode #3 - Property Graph Model

Training and Certification

Why Neo4j

Whiteboard Friendly

The real world is a graph of relationships — not tables of columns and rows.

Global Community

Support for popular languages & frameworks. Learn from books, meetups, and trainings.

Native Graph Performance

Optimized graph storage and processing with the expressive Cypher query language.

What It's Made of

Flexible Schema


Clustering for HA and Performance

Powerful Cypher Query Language

Neo4j Browser

Drivers for Popular Languages and Frameworks

Data Import


Upcoming Events Near You


    • How the ICIJ Used Neo4j to Unravel the Panama Papers - Mar Cabra
    • 5 minutes on Neo4j 3.0 - Announcement video
    • Better Data, Better Decisions – 1000x Faster with Neo4j.

    Neo4j in the Social Universe

    44.3k public Slack channel messages
    3.2k GitHub repos about Neo4j
    @CP90_: Been trying out Neo4j on my machine, have to say I'm impressed.
    1,638 developers have answered StackOverflow questions about Neo4j
    7430 topics on Google Groups

    GraphGist Projects