Databases 2 min read

PHP Neo4j Library (church/neo4j): Installation, Initialization, and Transaction Operations

This article introduces the PHP Neo4j library church/neo4j, outlines its PHP ≥ 7.4 environment requirements, shows how to install it via Composer, and provides detailed code examples for initializing the client, building statements, managing transactions, and running unit tests.

php Courses
php Courses
php Courses
PHP Neo4j Library (church/neo4j): Installation, Initialization, and Transaction Operations

Introduction

The church/neo4j library is a PHP client for Neo4j that simplifies connecting to the Neo4j HTTP API. It requires PHP ≥ 7.4.

Installation

Install the package with Composer: composer require church/neo4j Usage – Initialization

$app = new \Church\Neo4j\Application("http://127.0.0.1:7474", "neo4j", "neo4j");
$app->discovery();

Usage – Building a Query

$statement = (new \Church\Neo4j\Statement('CREATE (n $props) RETURN n)'))
    ->params([
        'props' => [
            'name' => 'test'
        ]
    ]);

Transaction Management

Add statements to a repository and start a transaction:

$statements = \Church\Neo4j\StatementRepository::add($statement);
$transaction = $app->transaction($statements);
$transaction->begin();

Commit the transaction and handle the response:

$result = $transaction->commit();
if ($result->getRawResponse()->getStatusCode() == 200) {
    print_r($result->getData());
}

Keep the transaction alive (default expiry is 60 seconds): $transaction->keepAlive(); Rollback if needed: $transaction->rollback(); Or begin and commit in a single call:

$result = $transaction->beginAndCommit();
print_r($result);

Unit Testing

composer install
./vendor/bin/phpunit

For more details, refer to the Neo4j HTTP API documentation at https://neo4j.com/docs/http-api/current/action/ .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

transactionLibraryNeo4j
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.