【问题标题】:No output from neo4j queryneo4j 查询没有输出
【发布时间】:2017-04-21 12:32:48
【问题描述】:

我正在尝试执行在此处找到的那种示例 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 的新手,所以请有人告诉我我做错了什么?

【问题讨论】:

    标签: php neo4j


    【解决方案1】:

    好的,这里的问题似乎是 CURL。通过在我的查询中使用占位符,例如A {Name:{Placeholder}},这似乎产生了输出。解决此类问题的解决方案似乎是将输出复制到命令行中并在那里以及在 PHP 中尝试。

    【讨论】:

      【解决方案2】:

      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));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多