開源圖形數據庫Neo4j使用 php開發

先看看它的示例數據php

打開 Neo4j Browsernode

:play movie graphgit

寫代碼,而後點play執行github

 

 

Cypher, the graph query language.Neo4j提供了Cypher查詢語言,它相似於關係型數據庫中的SQL語句。數據庫

(1) 建立一個節點:create (n: Person {name: "Dennis"}) return nide

 

插入一個Person類別的節點,且這個節點有一個屬性name,屬性值爲Andresui

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

 

 

插入邊。插入一條a到b的有向邊,且邊的類別爲Follow對象

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

 

(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

相關文章
相關標籤/搜索