phpdockercassandracqlshphpcassa

Cannot create keyspace with cassandra with php


I can't create keyspace on cassandra running under docker containor with PHP. The connexion seems to be ok but i have nothing created. when i run DESCRIBE keyspaces; i have only keyspaces created by default.

I'm using thobbs/phpcassa bundle to connect php with cassandra. I think that the problem seems to be with login and password.

In this bundle, i didn't found where i put them. When i connect to cassandra container, i can connect by this command cqlsh -u cassandra -p cassandra 172.24.0.1 9042

Bellow is my code on 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');

where i can put my login and password ?


Solution

  • Please don't use thobbs/phpcassa - it's very old, and it uses legacy Thrift protocol under the hood... The correct way is to work with Cassandra now is to use PHP driver from DataStax. Authentication is fully supported there (doc), like this:

    $cluster = Cassandra::cluster()
                   ->withCredentials("username", "password")
                   ->build();
    $session = $cluster->connect();
    

    And after you got $session, you can use execute function to execute CQL statements, like, CREATE KEYSPACE and CREATE TABLE, like this:

    $session->execute('CREATE TABLE ...')
    

    I recommend to learn about CQL (Cassandra Query Language) that replaced the Thrift long time ago. The good resource for it is "Cassandra. The definitive guide book" - the 3rd edition of it was recently released, and freely available from the DataStax site.