Search code examples
phppdocassandracql3

How to select * from users where key IN (<$array>); with PHP and Cassandra-PDO (cql3)?


I'm using https://github.com/Orange-OpenSource/YACassandraPDO as PDO extension, all works fine, but when i try to get records by clause select * from users Where key IN ($my_keys_array) just retrieves the first record.

$query = "SELECT * FROM questions WHERE user_id = 'mikko' AND question_id IN ('Question 1','Quesiton 2')";
$stmt = $this->db->prepare($query);
$stmt->execute ();
$res = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode($res);

Somebody knows if there is an issue with cassandra-pdo or where i'm wrong?

I try the same sentence by cqlsh> prompt and works fine.

Thanks in advance for any help.


Solution

  • At the moment you are fetching only single row from a result set, to fetch all rows you should issue $stmt->fetchAll () instead of $stmt->fetch().

    Btw. a good place to look at, how to use the API is always the tests: these can give quite a lot of information https://github.com/Orange-OpenSource/YACassandraPDO/tree/master/tests.

    You can also check the PDO documentation for fetch and fetchAll.