Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中访问cassandra集合_Php_Cassandra_Nosql - Fatal编程技术网

在php中访问cassandra集合

在php中访问cassandra集合,php,cassandra,nosql,Php,Cassandra,Nosql,这是我在cassandra数据库中创建的表 create table followers( username text, followedby list<text>, primary key(username)); 我不知道如何使用php存储查询结果,以便可以逐个访问列表中的所有元素,即在php中使用数组还是列表。下面是我尝试的代码之一 foreach($result as $row) { $ans=$row['followed']; echo $ans[0];

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

create table followers(
username text,
followedby list<text>,
primary key(username));
我不知道如何使用php存储查询结果,以便可以逐个访问列表中的所有元素,即在php中使用数组还是列表。下面是我尝试的代码之一

foreach($result as $row)
{
    $ans=$row['followed'];
    echo $ans[0];
    echo $ans[1];
}
但代码给出了以下错误:

无法在第68行的C:\wamp64\www\LoginRegistrationForm\home.php中将Cassandra\Collection类型的对象用作数组

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

foreach($result as $row)
{
    foreach ($row['followed'] as $followed) {
      echo "  {$followed}" . PHP_EOL;
    }
}
驱动程序返回集合类型的对象,您将其用作数组。。因此,它给了你错误

foreach($result as $row)
{
    foreach ($row['followed'] as $followed) {
      echo "  {$followed}" . PHP_EOL;
    }
}