无法使用 php 使用 cassandra 创建键空间
Cannot create keyspace with cassandra with php
我无法在 docker 容器 PHP 下的 cassandra 运行ning 上创建键空间。连接似乎没问题,但我没有创建任何东西。当我 运行 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 协议...现在使用 Cassandra 的正确方法是使用 PHP driver from DataStax. Authentication is fully supported there (doc) ,像这样:
$cluster = Cassandra::cluster()
->withCredentials("username", "password")
->build();
$session = $cluster->connect();
得到$session
后,可以使用execute
函数来执行CQL语句,比如CREATE KEYSPACE and CREATE TABLE,像这样:
$session->execute('CREATE TABLE ...')
我建议了解很久以前取代 Thrift 的 CQL(Cassandra 查询语言)。它的好资源是“Cassandra。权威指南”——它的第 3 版最近发布了,并且 freely available from the DataStax site.
我无法在 docker 容器 PHP 下的 cassandra 运行ning 上创建键空间。连接似乎没问题,但我没有创建任何东西。当我 运行 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 协议...现在使用 Cassandra 的正确方法是使用 PHP driver from DataStax. Authentication is fully supported there (doc) ,像这样:
$cluster = Cassandra::cluster()
->withCredentials("username", "password")
->build();
$session = $cluster->connect();
得到$session
后,可以使用execute
函数来执行CQL语句,比如CREATE KEYSPACE and CREATE TABLE,像这样:
$session->execute('CREATE TABLE ...')
我建议了解很久以前取代 Thrift 的 CQL(Cassandra 查询语言)。它的好资源是“Cassandra。权威指南”——它的第 3 版最近发布了,并且 freely available from the DataStax site.