/cassandra-php-driver

PHP Driver for ScyllaDB/Apache Cassandra

Primary LanguageCOtherNOASSERTION

ScyllaDB/CassandraDB Driver for PHP

Build Status: Linux Build Status: Windows

A modern, feature-rich and highly tunable PHP client library for Apache Cassandra 3.0+ using exclusively Cassandra's binary protocol.

This is a wrapper around the DataStax C/C++ Driver for Apache Cassandra.

Note: DataStax products do not support big-endian systems.

Getting the Driver

Binary versions of the driver, available for multiple operating systems and multiple versions of PHP, can be obtained from DataStax download server. You're also can compile the driver by yourself or use Dockerfile with a pre-set environment to run your tests.

What's new in v1.2.0/v1.3.8

Compatibility

This driver works exclusively with the Cassandra Query Language v3 (CQL3) and Cassandra's native protocol. The current version works with:

  • Apache Cassandra versions 3.0+
  • PHP 8.0, 8.1 and 8.2
  • 64-bit (x64)
  • Thread safe (TS) and non-thread safe (NTS)
  • Compilers: GCC 10.0+ and Clang 14+

Documentation

Getting Help

  • If you're able to fix a bug yourself, you can fork the repository and submit a pull request with the fix.
  • If you're not able fix a bug yourself, please open an issue , describe it with the most details possible and wait until one of our maintainers join the conversation.

Quick Start

<?php
$cluster   = Cassandra::cluster()                 // connects to localhost by default
                 ->build();
$keyspace  = 'system';
$session   = $cluster->connect($keyspace);        // create session, optionally scoped to a keyspace
$statement = new Cassandra\SimpleStatement(       // also supports prepared and batch statements
    'SELECT keyspace_name, columnfamily_name FROM schema_columnfamilies'
);
$querySent = $session->execute($statement);  
$result    = $querySent->get();                      // wait for the result, with an optional timeout

foreach ($result as $row) {                       // results and rows implement Iterator, Countable and ArrayAccess
    printf("The keyspace %s has a table called %s\n", $row['keyspace_name'], $row['columnfamily_name']);
}

Installation

Read detailed instructions on building and installing the extension

Or if you want to use a older version (PHP 7.1) use the command below

pecl install cassandra

Contributing

Read our contribution policy for a detailed description of the process.

Code examples

The DataStax PHP Driver uses the amazing Behat Framework for both end-to-end, or acceptance testing and documentation. All of the features supported by the driver have appropriate acceptance tests with easy-to-copy code examples in the features/ directory.

Running tests

For your convenience a Vagrantfile with configuration ready for testing is available. To execute tests, run the following:

git clone https://github.com/datastax/php-driver.git
cd php-driver
git submodule update --init
vagrant up
vagrant ssh

Once you've logged in to the vagrant VM, run:

cd /usr/local/src/php-driver
./bin/behat
./bin/phpunit

Copyright

© DataStax, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.