In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to use the PHP client to manipulate data through Neo4j's REST interface. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Neo4j is one of the most popular graph databases at present, which is based on computer graph structure and is good at dealing with complex data relations. Take, for example, the person-to-person diagram in our common social networks.
How to use PHP client to operate data through Neo4j's REST interface
We need to use the complex SQL statement above to get the list of actors who have performed with KevinBacon.
It's even more troublesome if we need to get a list of actors who have performed with people who have performed with KevinBacon. Imagine one more layer of actors who have performed with (actors who have performed with KevinBacon). It's an almost impossible task.
Let's directly use the PHP client of Neo4j to build the graph:
$client=newClient (newTransport ('localhost',7474))
/ / build actor nodes
$keanu=newNode ($client)
$keanu- > setProperty ('name','KeanuReeves')-> save ()
$laurence=newNode ($client)
$laurence- > setProperty ('name','LaurenceFishburne')-> save ()
$jennifer=newNode ($client)
$jennifer- > setProperty ('name','JenniferConnelly')-> save ()
$kevin=newNode ($client)
$kevin- > setProperty ('name','KevinBacon')-> save ()
How to use PHP client to operate data through Neo4j's REST interface
/ / build a movie node
$matrix=newNode ($client)
$matrix- > setProperty ('title','TheMatrix')-> save ()
$higherLearning=newNode ($client)
$higherLearning- > setProperty ('title','HigherLearning')-> save ()
$mysticRiver=newNode ($client)
$mysticRiver- > setProperty ('title','MysticRiver')-> save ()
/ / establish an association
$keanu- > relateTo ($matrix,'IN')-> save ()
$laurence- > relateTo ($matrix,'IN')-> save ()
$laurence- > relateTo ($higherLearning,'IN')-> save ()
$jennifer- > relateTo ($higherLearning,'IN')-> save ()
$laurence- > relateTo ($mysticRiver,'IN')-> save ()
$kevin- > relateTo ($mysticRiver,'IN')-> save ()
Then we can query the data on the graph structure that has been established. The first query is to find all other people whose distance from KevinBacon is 12 (the distance between actors and actors can only be a multiple of 2, because there is a movie between them).
$path=$keanu- > findPathsTo ($kevin)
-> setMaxDepth (12)
-> getSinglePath ()
Foreach ($pathas$i= > $node) {
If ($I% 2) {
Echo$node- > getProperty ('name')
If ($iSuppli 1 please count ($path)) {
Echo "wasin\ n"
}
} else {
Echo "\ t". $node- > getProperty ('title'). "with\ n"
}
}
You can also query all LaurenceFishburne-related movies with the following statement:
Echo$laurence- > getProperty ('name'). "wasin:\ n"
$relationships=$laurence- > getRelationships ('IN')
Foreach ($relationshipsas$relationship) {
$movie=$relationship- > getEndNode ()
Echo "\ t". $movie- > getProperty ('title'). "\ n"
}
This is the end of the article on "how to use the PHP client to manipulate data through Neo4j's REST interface". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.