我正在尝试执行此处的Neo4j代码示例: http://neo4j.com/docs/developer-manual/current/cypher/clauses/create/#create-create-a-full-path但是我似乎错过了一些明显的东西。我需要创建的是(A)有(B)。
$n4 = 'curl -H "Accept: application/json; charset=UTF-8" -s -u user:pass -H "Content-Type: application/json" -X POST http://localhost:7474/db/data/cypher -d \'%s\'';
function basicQuery($query){
global $n4;
$str = '{"query" : "'.$query.'","params" : {}}';
return sprintf($n4,$str);
}
$A = array('Label'=>'Attributes');
$B = array('Label'=>'Attributes');
$query = 'CREATE p =(A '.json_encode($A).')-[:HAS]->(B '.json_encode($B).') RETURN p';
echo shell_exec(basicQuery($query));
但我没有得到任何输出,当我跑步时:
shell_exec(basicQuery('MATCH (A) RETURN DISTINCT count(A) AS tally'));
我得到0的记录。我对neo4j很新,所以请有人告诉我我做错了什么?
答案 0 :(得分:0)
好的,这里的问题似乎是CURL。通过在我的查询中使用占位符(例如A {Name:{Placeholder}}
),这似乎会生成输出。解决此类问题的解决方案似乎是将输出复制到命令行并在那里和PHP中进行尝试。
答案 1 :(得分:0)
1)您不能在属性键名称
周围使用引号2)您需要正确编码查询
$n4 = 'curl -H "Accept: application/json; charset=UTF-8" -s -u user:pass -H "Content-Type: application/json" -X POST http://localhost:7474/db/data/cypher -d \'%s\'';
function basicQuery($query){
global $n4;
$json = array(
"query" => $query,
"params" => new stdClass
);
$str = json_encode($json);
return sprintf($n4, $str);
}
function objToMap($obj) {
$tmp = [];
foreach($obj as $key=>$value) {
$tmp[] = '`' . $key . '`: ' . json_encode($value);
}
return '{' . join(',', $tmp) . '}';
}
$A = array('Label'=>'Attributes');
$B = array('Label'=>'Attributes');
$query = 'CREATE p =(A:TEST ' .objToMap($A).')-[:HAS]->(B:TEST '.objToMap($B).') RETURN p';
echo shell_exec(basicQuery($query));