使用 Codeigniter 在 Neo4j 中计算行数

Count Rows in Neo4j with Codeigniter

我正在使用 Neo4j 和 Codeigniter,我必须在将某个节点添加到数据库之前检查它是否已经存在。

现在我正在这样做:

// find the address
$cypher = "MATCH (adr) WHERE adr.ip_address = '".$address."' RETURN count(adr) as c";

$res = $this->neo->execute_query($cypher);

foreach ($res as $r)
{
    $count = $r['c'];
}       

if ($count > 0){
  // ... some action here
}

我觉得一定有更好的方法来计算结果集中的记录。

您可以使用 CI 执行此操作:

$res->num_rows();

受@anustart 回答和错误消息的启发,我开始深入研究 neo4j 库并找到了这个解决方案:

  echo $res->count();

这正是我想要的。