1. Go to this page and download the library: Download uri2x/php-cql 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/ */
uri2x / php-cql example snippets
ssandraNative\Cassandra;
$obj = new Cassandra();
// Connects to the node:
$res = $obj->connect('127.0.0.1', 'my_user', 'my_pass', 'my_keyspace');
// Tests if the connection was successful:
if ($res)
{
// Queries a table:
$arr = $obj->query('SELECT col1, col2, col3 FROM my_table WHERE id=?',
Cassandra::CONSISTENCY_ONE,
[Cassandra::bind_param(1001, Cassandra::COLUMNTYPE_BIGINT]);
// $arr, for example, may contain:
// Array
// (
// [0] => Array
// (
// [col1] => first row
// [col2] => 1
// [col3] => 0x111111
// )
//
// [1] => Array
// (
// [col1] => second row
// [col2] => 2
// [col3] => 0x222222
// )
//
// )
// Prepares a statement:
$stmt = $obj->prepare('UPDATE my_table SET col2=?,col3=? WHERE col1=?');
// Executes a prepared statement:
$values = ['col2' => 5, 'col3' => '0x55', 'col1' => 'five'];
$pResult = $obj->execute($stmt, $values);
// Upon success, $pResult would be:
// Array
// (
// [0] => Array
// (
// [result] => success
// )
//
// )
// Closes the connection:
$obj->close();
}
// Connects to the node:
$handle = cassandra_connect('127.0.0.1', 'my_user', 'my_pass', 'my_keyspace');
// Tests if the connection was successful:
if ($handle)
{
// Queries a table:
$arr = cassandra_query($handle, 'SELECT col1, col2, col3 FROM my_table');
// Prepares a statement:
$stmt = cassandra_prepare($handle,
'UPDATE my_table SET col2=?,col3=? WHERE col1=?');
// Executes a prepared statement:
$values = ['col2' => 5, 'col3' => '0x55', 'col1' => 'five'];
$pResult = cassandra_execute($handle, $stmt, $values);
// Closes the connection:
cassandra_close($handle);
}
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.