开源图形数据库Neo4j使用 php开发

先看看它的示例数据

打开 Neo4j Browser

:play movie graph

写代码,然后点play执行

 

 

Cypher, the graph query language.Neo4j提供了Cypher查询语言,它类似于关系型数据库中的SQL语句。

(1) 创建一个节点:create (n: Person {name: "Dennis"}) return n

 

插入一个Person类别的节点,且这个节点有一个属性name,属性值为Andres

CREATE (n:Person { name : 'Andres'});

 

 

插入边。插入一条a到b的有向边,且边的类别为Follow

MATCH (a:Person),(b:Person) WHERE a.name = 'Node A' AND b.name = 'Node B' CREATE (a)-[r:Follow]->(b);

 

(2) 查询所有的Person节点:match (n: Person) return n

 

 

 

更新节点。更新一个Person类别的节点,设置新的name。

MATCH (n:Person { name: 'Andres' }) SET n.name = 'Taylor';

 

1.Create: insert movie data into the graph

create语句用于Insert graph data

 

 

 

2.Find: retrieve individual movies and actors

如:Find the actor named "Tom Hanks".

MATCH (tom {name: "Tom Hanks"}) RETURN tom

查询名为"Dennis"的Person节点:match (n: Person) where n.name="Dennis" return n

 

Find 10 people:

MATCH (people:Person) RETURN people.name LIMIT 10

 

List all Tom Hanks movies

MATCH (tom:Person {name: "Tom Hanks"})-[:ACTED_IN]->(tomHanksMovies) RETURN tom,tomHanksMovies

 

Tom Hanks' co-actors

MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) RETURN coActors.name

 

How people are related to "Cloud Atlas"

MATCH (people:Person)-[aaa]-(:Movie {title: "Cloud Atlas"}) RETURN people.name, Type(aaa)

 

3.Query: discover related actors and directors

 

MATCH p=shortestPath( (bacon:Person {name:"Kevin Bacon"})-[*]-(meg:Person {name:"Meg Ryan"}) ) RETURN p

 

MATCH (ms:Person { name:'Andres' }),(cs:Person { name:'Taylor' }), p = shortestPath((ms)-[r:Follow]-(cs)) RETURN p;

 

 

 

Delete all Movie and Person nodes, and their relationships:

MATCH (n) DETACH DELETE n

 

 

删除节点和与其相连的边。

MATCH (n:Person { name:'Andres' }) DETACH DELETE n;

 

删除边。

MATCH (a:Person)-[r:Follow]->(b:Person) WHERE a.name = 'Andres' AND b.name = 'Taylor' DELETE r;

 

 

:server connect命令用于连接

 

  • 查询两个节点之间的关系。

MATCH (a:Person { name:'Andres' })-[r]->(b:Person { name:'Taylor' }) RETURN type(r);

 

  • 查询一个节点的所有Follower。

MATCH (:Person { name:'Taylor' })-[r:Follow]->(Person) RETURN Person.name;

 

  • 查看所有的节点数和边数

MATCH (n) RETURN count(n); MATCH ()-->() RETURN count(*);

 

适合存储”修改较少,查询较多,没有超大节点(常见于大V)“的图数据。Arangodb也许是一个不错的考虑对象,根据其官网的说明,Arangodb不仅具有一般图形数据库的优点,而且在各种操作的速度上领先于Neo4j

用php开发

https://neo4j.com/developer/language-guides/

https://neo4j.com/developer/php/

 

 

https://neo4j.com/developer/example-project/

https://github.com/neo4j-examples?q=movies

 

 

 

dbms.security.auth_enabled=false

 

关系也可以有属性,而且有type类型。

 

用的这个

https://github.com/elesos/neo4jphp

 

[labels] => Array ( [0] => Person )

 

 

 

 

 

有没有知道如何多数据库切换?

Active database: graph.db

 

 

 

 

 

 

已标记关键词 清除标记
<div class="post-text" itemprop="text"> <p>i know this topic is Repetitious but I cant do it... ir run this in my cmd</p> <p>C:\Users\Asus> composer require graphaware/neo4j-php-client</p> <p>and i use this code:</p> <pre><code> <?php /** * To install Neo4j-PHP-Client, we use Composer * * $ curl -sS https://getcomposer.org/installer | php * $ php composer.phar require graphaware/neo4j-php-client * */ require 'C:\Users\Asus\vendor\autoload.php'; use GraphAware\Neo4j\Client\ClientBuilder; // change to your hostname, port, username, password $neo4j_url = "neo4j@bolt://localhost:11004"; // setup connection $client = ClientBuilder::create() ->addConnection('default', $neo4j_url) ->build(); // setup data $insert_query = <<<EOQ UNWIND {pairs} as pair MERGE (p1:Person {name:pair[0]}) MERGE (p2:Person {name:pair[1]}) MERGE (p1)-[:KNOWS]-(p2); EOQ; // friend data to insert $data = [["Jim","Mike"],["Jim","Billy"],["Anna","Jim"], ["Anna","Mike"],["Sally","Anna"],["Joe","Sally"], ["Joe","Bob"],["Bob","Sally"]]; // insert data $client->run($insert_query, ["pairs" => $data]); // friend of friend: query $foaf_query = <<<EOQ MATCH (person:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf) WHERE person.name = {name} AND NOT (person)-[:KNOWS]-(foaf) RETURN foaf.name AS name EOQ; // friend of friend: build and execute query $params = ['name' => 'Joe']; $result = $client->run($foaf_query, $params); foreach ($result->records() as $record) { echo $record->get('name') . PHP_EOL; } // common friends: query $common_friends_query = <<<EOQ MATCH (user:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf:Person) WHERE user.name = {user} AND foaf.name = {foaf} RETURN friend.name AS friend EOQ; // common friends: build and execute query $params = ['user' => 'Joe', 'foaf' => 'Sally']; $result = $client->run($common_friends_query, $params); foreach ($result->records() as $record) { echo $record->get('friend') . PHP_EOL; } // connecting paths: query $connecting_paths_query = <<<EOQ MATCH path = shortestPath((p1:Person)-[:KNOWS*..6]-(p2:Person)) WHERE p1.name = {name1} AND p2.name = {name2} RETURN [n IN nodes(path) | n.name] as names EOQ; // connecting paths: build and execute query $params = ['name1' => 'Joe', 'name2' => 'Billy']; $result = $client->run($connecting_paths_query, $params); foreach ($result->records() as $record) { print_r($record->get('names')); } </code></pre> <p>and i have this error Notice: Undefined index: scheme in C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php on line 77</p> <p>Notice: Undefined index: host in C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php on line 77</p> <p>Warning: stream_socket_client(): unable to connect to tcp://://:7687:7687 (The requested address is not valid in its context. ) in C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php on line 167</p> <p>Fatal error: Uncaught exception 'GraphAware\Bolt\Exception\IOException' with message 'Error to connect to the server(10049) : "The requested address is not valid in its context. "' in C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php:170 Stack trace: #0 C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php(189): GraphAware\Bolt\IO\StreamSocket->connect() #1 C:\Users\Asus\vendor\graphaware eo4j-bolt\src\Driver.php(114): GraphAware\Bolt\IO\StreamSocket->reconnect() #2 C:\Users\Asus\vendor\graphaware eo4j-bolt\src\Driver.php(98): GraphAware\Bolt\Driver->handshake() #3 C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php(164): GraphAware\Bolt\Driver->session() #4 C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Connection\Connection.php(115): GraphAware\Neo4j\Client\Connection\Connection->checkSession() #5 C:\Users\Asus\vendor\graphaware eo4j-php-client\src\Client.php(45): GraphAware\Neo4j\Client\Connection\Connection->run('UNWIND {pairs} ...', Array, NULL) #6 C in C:\Users\Asus\vendor\graphaware eo4j-bolt\src\IO\StreamSocket.php on line 170</p> </div>
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页