Installing the DataStax PHP driver
Pekka Enberg edited this page May 17, 2016
·
1 revision
Scylla uses the same drivers as Cassandra. To install the DataStax PHP driver, you first need to install the C++ driver:
git clone https://github.com/datastax/cpp-driver.git
cd cpp-driver
git checkout 2.2.2
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make
sudo make install
You can then install the PHP extension:
sudo pecl install cassandra
Remember to register the extension in php.ini
:
sudo sh -c "echo 'extension=cassandra.so' >> /etc/php.ini"
To test the PHP driver, create a PHP source file scylla.php
that looks as follows:
<?php
$cluster = Cassandra::cluster()->build();
$keyspace = 'system';
$session = $cluster->connect($keyspace);
$statement = new Cassandra\SimpleStatement('SELECT keyspace_name, columnfamily_name FROM schema_columnfamilies');
$future = $session->executeAsync($statement);
$result = $future->get();
foreach ($result as $row) {
printf("The keyspace %s has a table called %s\n", $row['keyspace_name'], $row['columnfamily_name']);
}
?>
Start up a Scylla node and run the example program:
$ php scylla.php