Home  >  Article  >  Backend Development  >  Share a neo4j (graph database) PHP library!

Share a neo4j (graph database) PHP library!

藏色散人
藏色散人forward
2022-07-28 14:53:063330browse

git project address church/neo4j: https://github.com/fireqong/neo4j

Introduction

Neo4j based on PHP Library, which can help you connect to neo4j's PHP library more conveniently. Source document link address neo4j http api: https://neo4j.com/docs/http-api/current/actions/

Installation Environmental requirements

PHP >= 7.4

Installation

composer require church/neo4j

Usage

Initialization

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

Query statement

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

Open transaction

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

Submit transaction

$result = $transaction->commit();

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

Extend transaction validity period

default expiry time is 60 seconds.$transaction->keepAlive();

Rollback

$transaction->rollback();

Open and commit transactions

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

Unit test

composer install
./vendor/bin/phpunit

The above is the detailed content of Share a neo4j (graph database) PHP library!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete