PHPackages                             paulmozo/php-cypher-query-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. paulmozo/php-cypher-query-builder

ActivePackage[Database &amp; ORM](/categories/database)

paulmozo/php-cypher-query-builder
=================================

A PHP library for generating Cypher queries to be used with Graph databases such as Neo4J

0.11(7y ago)44.2k1MITPHPPHP &gt;=7.0

Since May 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/paulmozo/php-cypher-query-builder)[ Packagist](https://packagist.org/packages/paulmozo/php-cypher-query-builder)[ RSS](/packages/paulmozo-php-cypher-query-builder/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (8)Used By (0)

php-cypher-query-builder
========================

[](#php-cypher-query-builder)

A PHP library for generating Cypher queries to be used with Graph databases such as Neo4J

NOTES
-----

[](#notes)

- This is a work in progress and there is still a lot to be done

Making cypher queries easily using the query builder
====================================================

[](#making-cypher-queries-easily-using-the-query-builder)

```
$client = new Moozla\QueryBuilder\Client();

$client
  ->match('Person', 'person')
  ->match('LIKES')
  ->match('Movie', 'movie')
  ->where('movie', 'name', "=", 'Taxi Driver')
  ->return('movie');

echo (string)$client;

```

Will output the string:

`MATCH (person:Person)-[:LIKES]-(movie:Movie) WHERE movie.name = "Taxi Driver" RETURN movie`

This project makes walking a graph easy. One of the main benefits is that it automatically figures out whether it needs to match a Node or a Relationship.

Running the tests
=================

[](#running-the-tests)

`./vendor/bin/phpunit tests/`

To do on this project
=====================

[](#to-do-on-this-project)

- Support more operators for the where clause
- Add more clauses such as "SET", "CREATE" and "DELETE"
- Add Directional relationships support
- More exceptions when invalid Cypher is detected
- Make this project available via packagist

Examples
========

[](#examples)

For a full list of examples look at the client tests found in `tests/ClientTests/`

Match Node-relation-Node and return all 3
-----------------------------------------

[](#match-node-relation-node-and-return-all-3)

```
$client = new Moozla\QueryBuilder\Client();

$client
  ->match('Person', 'person')
  ->match('LIKES', 'likes')
  ->match('Movie', 'movie')
  ->return('person')
  ->return('likes')
  ->return('movie');

echo (string)$client;

```

Will output the string:

`MATCH (person:Person)-[likes:LIKES]-(movie:Movie) RETURN person, likes, movie`

Match Node then add custom CYPHER to all clauses
------------------------------------------------

[](#match-node-then-add-custom-cypher-to-all-clauses)

```
$client = new Moozla\QueryBuilder\Client();

$client
  ->match('Person', 'person')
  ->appendToMatch('-[]->(:CustomMatch)')
  ->appendToWhere('(person)-[:KNOWS]-({name: 'Jeff'})')
  ->appendToReturn('count(person)');

echo (string)$client;

```

Will output the string:

`MATCH (person:Person)-[]->(:CustomMatch) WHERE (person)-[:KNOWS]-({name: 'Jeff'}) RETURN count(person)`

Note: All of the 'appendTo' methods will simply append the given string to the specified clause allowing for CYPHER not directly supported through the other query builder methods

Multi Match
-----------

[](#multi-match)

Sometimes with Cypher you need to match multiple parts of the graph before joining them. The query builder supports this

```
$client = new Moozla\QueryBuilder\Client();
$client
  ->match('Person', 'person')
  ->endMatch()
  ->match('Movie', 'movie')
  ->match('DIRECTED_BY')
  ->match('Director', 'director')
  ->where('director', 'name', '=', 'Ms Director')
  ->return('movie')
  ->return('person');

echo (string)$client;

```

Will output the following:

`MATCH (person:Person) MATCH (movie:Movie)-[:DIRECTED_BY]-(director:Director) WHERE director.name = "Ms Director" RETURN movie, person`

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2915d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/216037796?v=4)[pmozo](/maintainers/pmozo)[@pmozo](https://github.com/pmozo)

---

Top Contributors

[![paulmozo](https://avatars.githubusercontent.com/u/5136707?v=4)](https://github.com/paulmozo "paulmozo (6 commits)")

---

Tags

queryneo4jcypher

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/paulmozo-php-cypher-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/paulmozo-php-cypher-query-builder/health.svg)](https://phpackages.com/packages/paulmozo-php-cypher-query-builder)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11223.5M33](/packages/anourvalar-eloquent-serialize)[wikibase-solutions/php-cypher-dsl

A query builder for the Cypher query language

1861.7k5](/packages/wikibase-solutions-php-cypher-dsl)[graphaware/neo4j-common

Common Utilities library for Neo4j

25881.4k24](/packages/graphaware-neo4j-common)[neo4j/neo4j-bundle

Symfony integration for Neo4j

8272.5k](/packages/neo4j-neo4j-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
