Developer Guides Getting Started Getting Started What is a Graph Database? Intro to Graph DBs Video Series Concepts: RDBMS to Graph Concepts: NoSQL to Graph Getting Started Resources Neo4j Graph Platform Graph Platform Overview Neo4j Desktop Intro Neo4j Browser Intro… Read more →

Developer Guides

Want to Speak? Get $ back.

PHP: Neo4j Community Driver

Goals
If you are a PHP developer, this guide provides an overview of options for connecting to Neo4j. While this guide is not comprehensive it will introduce the different drivers and link to the relevant resources.
Prerequisites
You should be familiar with graph database concepts and the property graph model. You should have installed Neo4j and made yourself familiar with our Cypher Query language.
Intermediate

Neo4j Community Drivers

Members of the each programming language community have invested a lot of time and love to develop each one of the community drivers for Neo4j, so if you use any one of them, please provide feedback to the authors.

The community drivers have been graciously contributed by the Neo4j community. Many of them are fully featured and well-maintained, but some may not be. Neo4j does not take any responsibility for their usability.

Neo4j for PHP Developers

php logo

You’re a PHP developer and want to start with Neo4j? Here you go.

Whether you’re using frameworks like Symfony and Laravel or you’re developing without frameworks, you’ll find an adequate library for your use case.

If you have any questions, you can always find a community member around on the Neo4j Online Community.

Using Neo4j in a standalone PHP environment

If you prefer to develop without frameworks, these libraries are made for you:

GraphAware PHP Client

GraphAware PHP Client is a powerful and flexible PHP Client for Neo4j with MultiDB support, full High-Availability support for Neo4j Enterprise, and a convenient object formatter for handling graph results. The 4.0 release contains the following features:

  • Support for the Bolt binary protocol
  • Full-fledged Response Graph format
  • Full High-Availability support, with master re-election detection, slaves fallback built-in mechanism, and convenience methods for directing write and read queries to different databases.
  • Enterprise support by GraphAware
<?php

require_once 'vendor/autoload.php';

use GraphAware\Neo4j\Client\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687')
    ->build();
$query = "MATCH (n:Person)-[:FOLLOWS]->(friend) RETURN n.name, collect(friend) as friends";
$result = $client->run($query);

foreach ($result->getRecords() as $record) {
    echo sprintf('Person name is : %s and has %d number of friends', $record->value('name'), count($record->value('friends'));
}

Author

Christophe Willemsen

Example

https://github.com/neo4j-examples/movies-bolt-php

Package

composer require graphaware/neo4j-php-client:^4.0

Source

https://github.com/graphaware/neo4j-php-client

Docs

https://github.com/graphaware/neo4j-php-client/blob/master/README.md

GraphAware OGM for Neo4j and PHP

GraphAware Neo4j-PHP-OGM is an object graph mapper for Neo4j in PHP. Highly inspired by Doctrine2, it uses annotations to defined mapping and all the operations to the graph are centralized via an EntityManager.

<?php

namespace Movies;

use Doctrine\Common\Collections\ArrayCollection;
use GraphAware\Neo4j\OGM\Annotations as OGM;

/**
 * @OGM\Node(label="Movie")
 */
class Movie
{
    /**
     * @OGM\GraphId()
     * @var int
     */
    protected $id;

    /**
     * @OGM\Property(type="string")
     * @var string
     */
    protected $title;

    /**
     * @OGM\Property(type="string")
     * @var string
     */
    protected $tagline;

    /**
     * @OGM\Property(type="int")
     * @var int
     */
    protected $release;

    /**
     * @OGM\Relationship(type="ACTED_IN", direction="OUTGOING", targetEntity="Person", collection=true)
     * @var ArrayCollection|Person[]
     */
    protected $actors;

    /**
     * @param string $title
     * @param string|null $release
     */
    public function __construct($title, $release = null)
    {
        $this->title = $title;
        $this->release = $release;
        $this->actors = new ArrayCollection();
    }
    // Getters and Setters
<?php

$user = new User('cypher666');
/** @var Movie $movie */
$movie = $em->getRepository(Movie::class)->findOneBy('title', 'The Matrix');
$user->rateMovie($movie, '4.5');
$em->persist($user);
$em->flush();

Author

Christophe Willemsen

Package

composer require graphaware/neo4j-php-ogm

Source

https://github.com/graphaware/neo4j-php-ogm

Docs

https://github.com/graphaware/neo4j-php-ogm/blob/1.0/docs/01-intro.md

Neo4j Symfony Bundle

To provide a smooth integration between Neo4j and Symfony we’ve created the SymfonyNeo4jBundle. It wraps the excellent PHP community client by Graphaware and creates a solid Symfony experience. Thanks to the WebProfiler integration, you will see all your database calls, all the queries and their results, exceptions and statistics.

The bundle also integrates the client events with the Symfony event dispatcher. It is not opinionated in how you are using Neo4j and using the OGM is optional. Advanced Neo4j users will have full control over the client and what Cypher gets executed.

Authors

Tobias Nyholm, Xavier Coureau

Source

https://github.com/neo4j-contrib/neo4j-symfony

Docs

https://github.com/neo4j-contrib/neo4j-symfony/blob/master/README.md

https://github.com/neo4j-examples/movies-symfony-php-bolt

Blog

https://www.sitepoint.com/introducing-the-neo4j-symfony-bundle/

NeoEloquent for Laravel

Neo4j Graph Eloquent Driver for Laravel 4

Author

Abed Halawi

Source

https://github.com/Vinelab/NeoEloquent

Applications built with PHP and Neo4j

Omnomhub

Like for Github, but for recipes!

Author

Michelle Sanver

Source

https://github.com/Omnomhub/omnomhub

Thesaurus Manager

If you want to built your own thesaurus, this app is made for you

Author

Hasan Tayyar

Example

http://hasantayyar.github.io/thesaurus-manager

Source

https://github.com/okulbilisim/thesaurus-manager

Graphgen

Graph generation engine based on a Cypher DSL

Author

Christophe Willemsen

Source

https://github.com/graphaware/graphgen

Docs

http://graphgen.graphaware.com

The Example Project

The Neo4j example project is a small, one page webapp for the movies database built into the Neo4j tutorial. The front-end page is the same for all drivers: movie search, movie details, and a graph visualization of actors and movies. Each backend implementation shows you how to connect to Neo4j from each of the different languages and drivers.

You can learn more about our small, consistent example project across many different language drivers here. You will find the implementations for all drivers as individual GitHub repositories, which you can clone and deploy directly.

Neo4j Community Drivers

Members of the each programming language community have invested a lot of time and love to develop each one of the community drivers for Neo4j, so if you use any one of them, please provide feedback to the authors.

The community drivers have been graciously contributed by the Neo4j community. Many of them are fully featured and well-maintained, but some may not be. Neo4j does not take any responsibility for their usability.