我无法使用 PHP 在 docker 容器下运行的 cassandra 上创建 key 空间。连接似乎没问题,但我没有创建任何内容。当我运行 DESCRIBE keyspaces;
我只有默认创建的键空间。
我正在使用 thobbs/phpcassa
捆绑将 php 与 cassandra 连接起来。
我认为问题似乎与登录名和密码有关。
在这个捆绑包中,我没有找到我把它们放在哪里。当我连接到 cassandra 容器时,我可以通过这个命令进行连接 cqlsh -u cassandra -p cassandra 172.24.0.1 9042
贝娄是我在 index.php 上的代码
<?php
require 'vendor/autoload.php';
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
$servers = array("172.24.0.1:9042");
$pool = new ConnectionPool("Keyspace2", $servers);
$column_family = new ColumnFamily($pool, 'ColumnFamily1');
我可以把我的登录名和密码放在哪里?
最佳答案
请不要使用thobbs/phpcassa
- 它非常古老,并且在底层使用旧版 Thrift 协议(protocol)......现在使用 Cassandra 的正确方法是使用 PHP driver from DataStax .那里完全支持身份验证( doc ),如下所示:
$cluster = Cassandra::cluster()
->withCredentials("username", "password")
->build();
$session = $cluster->connect();
在你得到 $session
之后, 你可以使用 execute
执行 CQL 语句的函数,例如 CREATE KEYSPACE和 CREATE TABLE , 像这样:$session->execute('CREATE TABLE ...')
我建议学习很久以前取代 Thrift 的 CQL(Cassandra 查询语言)。它的好资源是“Cassandra。权威指南”——它的第 3 版最近发布了,freely available from the DataStax site .
关于php - 无法使用 cassandra 和 php 创建键空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62835967/