Cassandra exception when making CQL query to create new keyspace

88 views
Skip to first unread message

Silvio Iannone

unread,
Jan 15, 2014, 12:23:51 PM1/15/14
to phpc...@googlegroups.com
I'm using the following code to create a new keyspace in a Cassandra DB:

        use cassandra\Compression;
    use phpcassa\Connection\ConnectionPool;
    
    require_once($_SERVER["DOCUMENT_ROOT"]."/webname/resources/engine/settings.php");
    require_once(Settings\Path\Absolute::$library."/phpcassa/lib/autoload.php");
    
    // Set up DB connection
    $DBConnection = new ConnectionPool(
        "system",
        Settings\Database::$serverAddresses
    );
    $raw = $DBConnection->get();
    $raw->client->set_cql_version("3.1.0");
    
    // Start DB set up
    $query = "CREATE KEYSPACE \"WebName\" WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 3};";
    var_dump($query);
    $raw->client->execute_cql_query($query, Compression::NONE);

    $raw->close();

Problem is that i always get an `cassandra\InvalidRequestException` whenever i try to run the query.

I also tried to run that query in `cqlsh` and it works flawlessly.

The query is:

        CREATE KEYSPACE WebName WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 3};

Tyler Hobbs

unread,
Jan 15, 2014, 3:24:50 PM1/15/14
to phpc...@googlegroups.com
I'm not exactly sure why it works in cqlsh, but the "3" needs to be in single quotes, like so:

    $query = "CREATE KEYSPACE \"WebName\" WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : '3'};";

Also, I'll remind everybody that phpcassa does not officially support cql3.


--
You received this message because you are subscribed to the Google Groups "phpcassa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phpcassa+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Tyler Hobbs
DataStax

Silvio Iannone

unread,
Jan 16, 2014, 2:42:18 AM1/16/14
to phpc...@googlegroups.com
Thank you for your reply, but if PHPCASSA does not officially support CQL3, is there a way in PHP to make CQL3 requests?

I know that Datastax has developed a C# and a Java driver, but what about a PHP driver?

Thank you again for your time.

Tyler Hobbs

unread,
Jan 20, 2014, 1:05:53 PM1/20/14
to phpc...@googlegroups.com

On Thu, Jan 16, 2014 at 1:42 AM, Silvio Iannone <linuxis...@gmail.com> wrote:
Thank you for your reply, but if PHPCASSA does not officially support CQL3, is there a way in PHP to make CQL3 requests?

I know that Datastax has developed a C# and a Java driver, but what about a PHP driver?

Right now there's not a great way (that I'm aware of) to make CQL3 queries through PHP.  I'm at DataStax, and I do know that we plan to make a first-class PHP driver (probably by wrapping https://github.com/datastax/cpp-driver), but it may be another year before there's a stable CQL3 PHP driver.

My suggestion is to continue using the normal phpcassa API for now.


--
Tyler Hobbs
DataStax
Reply all
Reply to author
Forward
0 new messages