我用于以下命令行:
: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中添加此命令?
答案 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();