Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/31/2017

Reading time:2 min

DataStax PHP Driver

by John Doe

A modern, feature-rich and highly tunable PHP client library forApache Cassandra 2.1+ using exclusively Cassandra's binary protocol andCassandra Query Language v3. Use the DSE PHP driver for better compatibilityand support for DataStax Enterprise.This is a wrapper around the DataStax C/C++ Driver for Apache Cassandra.Note: DataStax products do not support big-endian systems.Getting the DriverBinary versions of the driver, available for multiple operating systems andmultiple versions of PHP, can be obtained from our [download server]. Thesource code is made available via GitHub. If using DataStax Enterpriseuse the DSE PHP driver instead.What's new in v1.2.0/v1.3.0CompatibilityThis driver works exclusively with the Cassandra Query Language v3 (CQL3) andCassandra's native protocol. The current version works with:Apache Cassandra versions 2.1, 2.2 and 3.0+PHP 5.6, PHP 7.0, and PHP 7.132-bit (x86) and 64-bit (x64)Thread safe (TS) and non-thread safe (NTS)Compilers: GCC 4.1.2+, Clang 3.4+, and MSVC 2010/2012/2013/2015If using DataStax Enterprise the DSE PHP driver provides more features andbetter compatibility.DocumentationGetting HelpJIRA: https://datastax-oss.atlassian.net/browse/PHPMailing List: https://groups.google.com/a/lists.datastax.com/forum/#!forum/php-driver-userDataStax Academy via Slack: https://academy.datastax.com/slackFeedback RequestedHelp us focus our efforts! Provide your input on the PHP Driver Platformand Runtime Survey (we kept it short).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 the result, with an optional timeoutforeach ($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']);}Installationpecl install cassandraRead detailed instructions on building and installing theextensionContributingRead our contribution policy for a detailed descriptionof the process.Code examplesThe DataStax PHP Driver uses the amazing Behat Framework for both end-to-end,or acceptance testing and documentation. All of the features supported by thedriver have appropriate acceptance tests with easy-to-copy code examples inthe features/ directory.Running testsFor your convenience a Vagrantfile with configuration ready for testing isavailable. To execute tests, run the following:git clone https://github.com/datastax/php-driver.gitcd php-drivergit submodule update --initvagrant upvagrant sshOnce you've logged in to the vagrant VM, run:cd /usr/local/src/php-driver./bin/behat./bin/phpunitCopyrightCopyright 2015-2017 DataStax, Inc.Licensed under the Apache License, Version 2.0 (the "License"); you may not usethis file except in compliance with the License. You may obtain a copy of theLicense athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributedunder the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES ORCONDITIONS OF ANY KIND, either express or implied. See the License for thespecific language governing permissions and limitations under the License.

Illustration Image

Build Status: Linux Build Status: Windows

A modern, feature-rich and highly tunable PHP client library for Apache Cassandra 2.1+ using exclusively Cassandra's binary protocol and Cassandra Query Language v3. Use the DSE PHP driver for better compatibility and support for DataStax Enterprise.

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 our [download server]. The source code is made available via GitHub. If using DataStax Enterprise use the DSE PHP driver instead.

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

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 2.1, 2.2 and 3.0+
  • PHP 5.6, PHP 7.0, and PHP 7.1
    • 32-bit (x86) and 64-bit (x64)
    • Thread safe (TS) and non-thread safe (NTS)
  • Compilers: GCC 4.1.2+, Clang 3.4+, and MSVC 2010/2012/2013/2015

If using DataStax Enterprise the DSE PHP driver provides more features and better compatibility.

Documentation

Getting Help

Feedback Requested

Help us focus our efforts! Provide your input on the PHP Driver Platform and Runtime Survey (we kept it short).

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 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

pecl install cassandra

Read detailed instructions on building and installing the extension

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-2017 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.

Related Articles

packages
cassandra
admin-monitor

DataStax Enterprise OpsCenter

John Doe

7/24/2018

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

libraries