使用PHP将json从Neo4j数据库导出到文件

时间:2015-08-13 20:09:56

标签: php json neo4j neoxygen

我用于以下命令行:

:POST /db/data/transaction/commit {"statements":[{"statement":"match n return n"}]}

当我将此查询设置为PHP变量时,我收到以下错误:

Fatal error: Uncaught exception 'Neoxygen\NeoClient\Exception\Neo4jException' with message 'Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Invalid input ':' in C:\wamp\www\PhpProjectNeo4j1\vendor\neoxygen\neoclient\src\Extension\AbstractExtension.php on line 88

您能否向我解释如何在PHP中添加此命令?

1 个答案:

答案 0 :(得分:0)

你看过NeoClient文档吗?

单一用法是:

$result = $client->sendCypherQuery('MATCH (n) RETURN n')->getResult();

如果你想导出到json,客户端没有魔法,只需使用返回的节点对象,创建一个数组并将其编码为json:

$nodes = [];
foreach ($result->getNodes() as $node) {
  $nodes[] = [
            'id' => $node->getId(),
            'labels' => $node->getLabels(),
            'properties' => $node->getProperties()
            ];
}

var_dump(json_encode($nodes));

编辑:

要获得结果对象,您需要启用ResponseFormatting服务:

示例:

$client = ClientBuilder::create()
    ->addDefaultLocalConnection()
    ->setAutoFormatResponse(true)
    ->build();