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

  • Play Video
    Intro to Graph Databases Episode #1 - Evolution of DBs
  • Play Video
    Intro to Graph Databases Episode #2 - Properties of Graph DBs & Use Cases
  • Play Video
    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


    • Play Video
      Data Structures and Algorithms: Linked Lists, Trees, Hash Maps
    • Play Video
      Exploring the WorldCup Graph with Neo4j Bloom
    • Play Video
      Neo4j Bloom: Investigating Patterns in Financial Transactions

    Neo4j in the Social Universe

    44.3k public Slack channel messages
    3.2k GitHub repos about Neo4j
    @david_cornelson: Hey Jim. Watched the evolution video you guys have done a great job on Neo4j and the Cypher query language. I'm bui… https://t.co/s46fuowj1v
    1,638 developers have answered StackOverflow questions about Neo4j
    7430 topics on Google Groups

    GraphGist Projects