在php中访问cassandra集合
这是我在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];
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;
}
}