cassandradatastax-php-driver

Datastax Cassandra PHP Driver : How to know CQL INSERT,UPDATE,DELETE are Successful


I am using Datastax php-driver to run CQL on my cassandra. I use INSERT,UPDATE,DELETE operation.

Below is sample code I run for insert

        $cluster = Cassandra::cluster()
                ->withContactPoints('54.XX.XX.XX', '54.XX.XX.XX','54.XX.XX.XX')
                ->withDefaultConsistency(4)
                ->build();

        $session = $cluster->connect('Sample_Key_Space');
        $statement = new Cassandra\SimpleStatement('insert_query');
        $result = $session->execute($statement);

My Question is, How to know the insert(or update,delete) is successful. I have read Datastax document and know that $session->execute return Cassandra\Rows, using this Rows object "How to judge my CQL is successful or Failed?".

Any help or inputs are much appreciated...

UPDATES:

Based on the answer, the working code samples

try {
$cluster = Cassandra::cluster()
            ->withContactPoints('54.XX.XX.XX')
            ->withDefaultConsistency(4)
            ->build();

    $session = $cluster->connect('school');

    $statement = new Cassandra\SimpleStatement("UPDATE1 activities SET activity_by = 'nagarajan' WHERE master_id = 12 AND activity_type='Hello' AND activity_id=10");
$result = $session->execute($statement);
return true;
} catch (Cassandra\Exception $e $e) {
    return 'failed';
}

Solution

  • Surround the execute method with try catch. If the query fails execute method throws exception which you can check in your application.

    For more details visit Session.Execute .