Skip to content
michaltrmac edited this page Nov 28, 2014 · 1 revision

Examples

Minimal Working Example - simple query against system.schema_keyspaces.

// Suppose you have the Cassandra cluster at 127.0.0.1, 
// listening at default port (9042).
$builder  = new CqlBuilder();
$builder->addContactPoint("127.0.0.1");

// Now build a model of cluster and connect it to DB.
$cluster  = $builder->build();
$session  = $cluster->connect();

// Write a query, switch keyspaces.
$query    = new CqlQuery('SELECT * FROM system.schema_keyspaces');

// Send the query.
$future   = $session->query($query);

// Wait for the query to execute; retrieve the result.
$future->wait();
$result   = $future->getResult();

if (null === $future->getError()) {

	echo "rowCount: {$result->getRowCount()}\n";
	
	while ($result->next()) {
		echo "strategy_options: " . $result->get("strategy_options") . "\n";
                // or you can use $result->get() to get complete row as associative array
                // var_dump($result->get());

                // or get column by name and specified column type
		echo "strategy_options: " . $result->get("strategy_options", Cql::CQL_COLUMN_TYPE_TEXT) . "\n";                
	}
	
}

// Boilerplate: close the connection session and perform the cleanup.
$session->close();
$cluster->shutdown();

Constants

Cql::CQL_CONSISTENCY_ANY;
Cql::CQL_CONSISTENCY_ONE;
Cql::CQL_CONSISTENCY_TWO;
Cql::CQL_CONSISTENCY_THREE;
Cql::CQL_CONSISTENCY_QUORUM;
Cql::CQL_CONSISTENCY_ALL;
Cql::CQL_CONSISTENCY_LOCAL_QUORUM;
Cql::CQL_CONSISTENCY_EACH_QUORUM;
Cql::CQL_CONSISTENCY_DEFAULT;

Cql::CQL_COLUMN_TYPE_UNKNOWN;
Cql::CQL_COLUMN_TYPE_CUSTOM;
Cql::CQL_COLUMN_TYPE_ASCII;
Cql::CQL_COLUMN_TYPE_BIGINT;
Cql::CQL_COLUMN_TYPE_BLOB;
Cql::CQL_COLUMN_TYPE_BOOLEAN;
Cql::CQL_COLUMN_TYPE_COUNTER;
Cql::CQL_COLUMN_TYPE_DECIMAL;
Cql::CQL_COLUMN_TYPE_DOUBLE;
Cql::CQL_COLUMN_TYPE_FLOAT;
Cql::CQL_COLUMN_TYPE_INT;
Cql::CQL_COLUMN_TYPE_TEXT;
Cql::CQL_COLUMN_TYPE_TIMESTAMP;
Cql::CQL_COLUMN_TYPE_UUID;
Cql::CQL_COLUMN_TYPE_VARCHAR;
Cql::CQL_COLUMN_TYPE_VARINT;
Cql::CQL_COLUMN_TYPE_TIMEUUID;
Cql::CQL_COLUMN_TYPE_INET;
Cql::CQL_COLUMN_TYPE_LIST;
Cql::CQL_COLUMN_TYPE_MAP;
Cql::CQL_COLUMN_TYPE_SET;