PHP code example of intermaterium / cassandra-native
1. Go to this page and download the library: Download intermaterium/cassandra-native 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/ */
intermaterium / cassandra-native example snippets
$clusterBuilder = new \CassandraNative\Cluster\ClusterBuilder();
$cassandra = $clusterBuilder->build();
$clusterBuilder = new \CassandraNative\Cluster\ClusterBuilder();
$clusterBuilder->withContactPoints(['1.0.0.0', '2.0.0.0']);
$cassandra = $clusterBuilder->build();
$authProvider = new \CassandraNative\Auth\PasswordAuthenticator('cassandra', 'cassandra');
$clusterBuilder->withCredentials($authProvider);
class KeberosProvider implements \CassandraNative\Auth\AuthProviderInterface
{
public function mechanism(): string
{
return 'java class name';
}
public function response(): string
{
return 'i am an initial response';
}
}
$stmt = new \CassandraNative\Statement\SimpleStatement('DESCRIBE TABLES');
$rows = $cassandra->execute($stmt);
$stmt = new \CassandraNative\Statement\SimpleStatement('SELECT col1, col2, col3 FROM my_table WHERE id=?')
$rows = $cassandra->execute(
$stmt,
[
[1001, Cassandra::COLUMNTYPE_BIGINT]
]
);
// Or
$stmt = new \CassandraNative\Statement\SimpleStatement('SELECT col1, col2, col3 FROM my_table WHERE id=:id')
$rows = $cassandra->execute(
$stmt,
[
'id' => [1001, Cassandra::COLUMNTYPE_BIGINT]
]
);