【发布时间】: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 中的数组
什么是正确的方法,以便我可以一一访问列表中的所有元素?
【问题讨论】: