【问题标题】:accessing collections of cassandra in php在 php 中访问 c​​assandra 的集合
【发布时间】:2017-11-28 07:40:50
【问题描述】:

这是我在 cassandra 数据库中创建的表

create table followers(
username text,
followedby list<text>,
primary key(username));

使用 php 我必须访问特定用户名 ($user="raj") 的关注者列表。以下是我正在使用的查询

$result=$session->execute(new Cassandra\SimpleStatement("select followedby from followers where username='$user'"));

我不知道如何使用 php 存储查询结果,以便可以一一访问列表中的所有元素,即在 php 中使用数组还是列表。以下是我尝试过的代码之一。

foreach($result as $row)
{
    $ans=$row['followed'];
    echo $ans[0];
    echo $ans[1];
}

但是代码给出了以下错误:

不能在第 68 行使用 Cassandra\Collection 类型的对象作为 C:\wamp64\www\LoginRegistrationForm\home.php 中的数组

什么是正确的方法,以便我可以一一访问列表中的所有元素?

【问题讨论】:

    标签: php cassandra nosql


    【解决方案1】:
    foreach($result as $row)
    {
        foreach ($row['followed'] as $followed) {
          echo "  {$followed}" . PHP_EOL;
        }
    }
    

    驱动程序返回 Collection 类型的对象,并且您将其用作数组..因此它会给您错误。

    Cassandra Collection in PHP

    【讨论】:

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