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();

$cassandra->connect('system');

$sslBuilder = new \CassandraNative\SSL\SSLBuilder();
$sslBuilder
    ->withClientCert(__DIR__ . '/certs/localhost.cer')
    ->withPrivateKey(__DIR__ . '/certs/localhost.key.pem');
    ->withTrustedCerts(__DIR__ . '/certs/localhost.cer.pem');

$clusterBuilder->withSSL($sslBuilder->build());

$clusterBuilder->withCompression(true);

$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]
    ]
);

$stmt = $cassandra->prepare('UPDATE my_table SET col2=?,col3=? WHERE col1=?');
$values = ['col2' => 5, 'col3' => '0x55', 'col1' => 'five'];
$rows = $cassandra->execute($stmt, $values);