PHP查詢圖數據庫neo4j,通過composer安裝,symfony、laravel皆可

資料:neo4j的phper

Composer安卓php調用neo4j的擴展。Github:Link

一、安裝

github上使用的Symfony框架,而我使用的是laravel框架,不影響框架都遵循psr,自動加載規則。

1、安裝即可,neo4j新版就是支持 bolt 連接的4.0版本。老的neo4j只支持http連接,很多php的擴展都老舊了,用不了。

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

2、具體方法參考github就好了,使用就是這麼使用。

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GraphAware\Neo4j\Client\ClientBuilder;

class Neo4jController extends Controller
{
    public $client = null;

    public function __construct() {
        $this->client = ClientBuilder::create()
            ->addConnection('bolt', 'bolt://192.168.3.22:7687') // Example for BOLT connection configuration (port is optional)
            ->build();
    }

    public function search(Request $request){
        $searchTerm = $request->get('q');
        $queryTemplate = 'MATCH p=(pe:person)-[r1:has]-(p1:phone)-[r2:registered]-(z1:zello) RETURN p limit 10';

        $results = $this->client->run($queryTemplate);

        $records = $results->getRecords();
    }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章