加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Cassandra(CQL)select语句,其中’where’不起作用

发布时间:2020-12-13 14:15:00 所属栏目:PHP教程 来源:网络整理
导读:我最近几天在使用Cassandra.我正在使用 PHPCassa库. 当我尝试使用以下代码时,它无法正常工作. require_once('phpcassa/connection.php'); require_once "phpcassa/columnfamily.php"; // Create new ConnectionPool like you normally would $pool = new Con
我最近几天在使用Cassandra.我正在使用 PHPCassa库.

当我尝试使用以下代码时,它无法正常工作.

require_once('phpcassa/connection.php');
 require_once "phpcassa/columnfamily.php";

 // Create new ConnectionPool like you normally would
 $pool = new ConnectionPool("newtest");

 // Retrieve a raw connection from the ConnectionPool
 $raw = $pool->get();

 $rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE KEY='phpqa'",cassandra_Compression::NONE);

 echo "<pre>";
 print_r($rows);
 echo "<pre>";

// Return the connection to the pool so it may be used by other callers. Otherwise,// the connection will be unavailable for use.
$pool->return_connection($raw);
unset($raw);

它没有返回,我也尝试过以下查询

$rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE age='32'",cassandra_Compression::NONE);
$rows = $raw->client->execute_cql_query("SELECT * FROM User WHERE name='jack'",cassandra_Compression::NONE);

但是当我尝试的时候

$rows = $raw->client->execute_cql_query("SELECT * FROM User",cassandra_Compression::NONE);

给出正确答案,显示所有行.请告诉我,如何正确使用’WHERE’.

Keyspace细节

Strategy Class:     org.apache.cassandra.locator.SimpleStrategy
Strategy Options:   None
Replication Factor: 1

Ring

   Start Token: 6064078270600954295
   End Token: 6064078270600954295
   Endpoints: 127.0.0.1
在cassandra你不能像平时一样查询’table’.您需要为可能要查询的每个列设置二级索引.

假设我们有一张桌子:

key      | User |   Age 
----------+----------------
 phpqa    | Jack |   20

您可以直接在密钥上查询:

SELECT * FROM User WHERE key='phpqa';

但是要执行其他WHERE查询,您需要在WHERE子句中可用的列上使用二级索引.

您可以做些什么来使您的查询灵活变通:

> Secondary indexes如上所述.
>使用复合列作为键.如果您只想查询2-3列,那么这是一个好主意,但是阅读this article详细说明了如何以及何时使用复合键,这里有一个如何在phpcassa中实现它的链接.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读