简体   繁体   English

使用Codeigniter计算Neo4j中的行数

[英]Count Rows in Neo4j with Codeigniter

I am using Neo4j and Codeigniter and I have to check if a certain node already exists before adding it to the DB. 我正在使用Neo4j和Codeigniter,必须先检查某个节点是否已存在,然后才能将其添加到数据库中。

Right now I am doing this: 现在我正在这样做:

// 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
}

I feel there must be a better way of counting records in a resultset. 我觉得必须有一种更好的方法来统计结果集中的记录。

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

$res->num_rows();

Inspired by @anustart answer and the error message I started digging through the neo4j library and found this solution: 受@anustart答案和错误消息的启发,我开始浏览neo4j库并找到以下解决方案:

  echo $res->count();

which does exactly what I was looking for. 正是我想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM