/php-driver

DataStax PHP Driver for Apache Cassandra

Primary LanguageCOtherNOASSERTION

DataStax PHP Driver for Apache Cassandra

Build Status

This is a wrapper around the DataStax C/C++ driver for Apache Cassandra. This driver works exclusively with the Cassandra Query Language version 3 (CQL3) and Cassandra's native protocol.

Status of v1.0.0.alpha

The current release is an early alpha. This means that it lacks some features and stability, but should be enough to start testing and working with Apache Cassandra. Below, you'll find a list of functionality that is already supported as well as what's planned for the upcoming releases.

Features

Planned

  • Windows support.
  • Expose Schema Metadata.
  • Add arithmetic functions to numeric types.

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'
);
$future    = $session->executeAsync($statement);  // fully asynchronous and easy parallel execution
$result    = $future->get();                      // wait for result to become available, optionally set a 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

NOTE: You must first install and enable the cassandra.so PHP extension.

  • First, get composer.
  • Then, install the DataStax PHP Driver for Apache Cassandra:
composer require datastax/php-driver 1.0.0-alpha

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 1.2, 2.0 and partially 2.1
  • DataStax Enterprise 3.1, 3.2, 4.0 and 4.5
  • PHP 5.3+

NOTE: Apache Cassandra 2.1 support is limited to the Cassandra 2.0 API, e.g. no user-defined types.

NOTE: Windows support is planned for a later, more stable release.

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

Copyright 2015 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.