neo4j的php客户端neoclient连接和使用

neo4j的php客户端neoclient连接和使用


1.下载安装

neo4j安装 neo4j 2.3.0M02 请见:http://blog.csdn.net/xubo245/article/details/50000967

neoclient的下载:https://github.com/neoxygen/neo4j-neoclient

安装:

composer require neoxygen/neoclient
需要提前安装好composer,请见:http://blog.163.com/wang_7380031@126/blog/static/55905870201503024412757/


2.运行:

将src下面的所有文件copy到/tests/Neoxygen/NeoClient下,

在test下新建1.php,写入:

<?php
echo "hello php neo4j 1</br>";
require_once 'vendor/autoload.php';

use Neoxygen\NeoClient\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('default','http','localhost',7474,true,'neo4j','password')
    ->setAutoFormatResponse(true)
    ->setDefaultTimeout(200)
    ->build();

测试是否连接上:

$version = $client->getNeo4jVersion();
echo $version;

返回结果:

2.3.0-M02

说明已经连接上


3.使用:

(1)创建节点并返回:

$query = 'CREATE (user:User {name:"Kenneth"}) RETURN user';
$result = $client->sendCypherQuery($query)->getResult();

$user = $result->getSingleNode();
$name = $user->getProperty('name');

返回结果:

Kenneth


(2)查找

$query = 'match n return n';
$result = $client->sendCypherQuery($query)->getResult();

$user = $result->getSingleNode();
$name = $user->getProperty('name');

返回结果:

Kenneth


(3)创建relationship:

echo $name;
$query = 'MATCH (user1:User {name:"Kenneth"}), (user2:User {name:"Kenneth"}) CREATE (user1)-[:FOLLOWS]->(user2)';
$params = ['user1' => 'Kenneth', 'user2' => 'Maxime'];
#$client->sendCypherQuery($query, $params);
$client->sendCypherQuery($query);

查看结果((1)创建了两个):


更多请见:http://www.sitepoint.com/discover-graph-databases-neo4j-php/?utm_source=tuicool&utm_medium=referral




【1】http://blog.csdn.net/xubo245/article/details/50000967

【2】http://blog.163.com/wang_7380031@126/blog/static/55905870201503024412757/

【3】http://www.sitepoint.com/discover-graph-databases-neo4j-php/?utm_source=tuicool&utm_medium=referral



已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页