Reputation: 115
here is the table I have created in cassandra database
create table followers(
username text,
followedby list<text>,
primary key(username));
using php I have to access the list of followers for a particular username($user="raj"). Below is the query I am using
$result=$session->execute(new Cassandra\SimpleStatement("select followedby from followers where username='$user'"));
I could not figure out how to store the result of the query using php so that all the elements in the list can be accessed one by one i.e. whether to use array or list in php. Below is one of the codes I tried.
foreach($result as $row)
{
$ans=$row['followed'];
echo $ans[0];
echo $ans[1];
}
but the code gave the following error:
Cannot use object of type Cassandra\Collection as array in C:\wamp64\www\LoginRegistrationForm\home.php on line 68
What is the correct method so that I can access all the elements in the list one by one?
Upvotes: 0
Views: 219
Reputation: 6218
foreach($result as $row)
{
foreach ($row['followed'] as $followed) {
echo " {$followed}" . PHP_EOL;
}
}
Driver returns object of type Collection and you are using it as an array.. hence it is giving you error.
Upvotes: 1