Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use PHP client to operate data through Neo4j's REST interface

2025-01-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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report