PHP code example of m6web / cassandra-bundle
1. Go to this page and download the library: Download m6web/cassandra-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
m6web / cassandra-bundle example snippets
// config/bundles.php
return [
\M6Web\Bundle\CassandraBundle\M6WebCassandraBundle::class => ['all' => true],
];
$cassandra = $this->get('m6web_cassandra.client.myclient');
$prepared = $cassandra->prepare("INSERT INTO test (id, title) VALUES(?, ?)");
$batch = new Cassandra\BatchStatement(Cassandra::BATCH_LOGGED);
$batch->add($prepared, ['id' => 1, 'title' => 'my title']);
$batch->add($prepared, ['id' => 2, 'title' => 'my title 2']);
$cassandra->execute($batch);
$statement = new Cassandra\SimpleStatement('SELECT * FROM test');
$result = $cassandra->execute($statement);
foreach ($result as $row) {
// do something with $row
}
$statement = new Cassandra\SimpleStatement('SELECT * FROM test');
$result = $cassandra->executeAsync($statement);
// do something while cassandra query running
foreach($result->get() as $row) {
// do something with row
}
use M6Web\Bundle\CassandraBundle\Cassandra\Type as TypeUtils;
$datetime = TypeUtils::getDateTimeFromTimeuuidString('513a5340-6da0-11e5-815e-93ec150e89fd');
if (is_null($datetime)) {
// something is wrong with supplied uuid
} else {
echo $datetime->format(\DateTime::W3C); // 2015-10-08 11:38:22+02:00
}