Giter Site home page Giter Site logo

php-cassandra's Introduction

php-cassandra - PHP Driver/Extension For Apache Cassandra (alpha)

A PHP driver for Apache Cassandra. This driver works exclusively with the Cassandra Query Language version 3 (CQL3) and Cassandra's binary protocol.

Building

The library use official c++ driver by DataStax https://github.com/datastax/cpp-driver Before build php-cassandra you should download and install DataStax C++ Driver for Apache Cassandra.

git clone https://github.com/datastax/cpp-driver.git
cd cpp-driver
cmake . && make && make cql_demo && make cql_test && make test && make install
git clone https://github.com/aparkhomenko/php-cassandra.git
cd php-cassandra
phpize && ./configure && make

After make you can check extension and see cassandra module

php -d="extension=modules/cassandra.so" -m

##Troubleshooting Common Problems

  • If you'll see the message
PHP Warning: PHP Startup: Unable to load dynamic library 'modules/cassandra.so' - libcql.so.0: cannot open shared object file: No such file or directory in Unknown on line 0

Try to add path to cql library. On Debian system cql library installed to /usr/local/lib

LD_LIBRARY_PATH=/usr/local/lib php -d="extension=modules/cassandra.so" -m

Or you can create symlink

sudo ln -s /usr/local/lib/libcql.so.0 /usr/lib/libcql.so.0

Don't forget to add extension to your php.ini if you'll try next example

Examples

Minimal Working Example - simple query against system.schema_keyspaces.

// Suppose you have the Cassandra cluster at 127.0.0.1, 
// listening at default port (9042).
$builder  = new CqlBuilder();
$builder->addContactPoint("127.0.0.1");

// Now build a model of cluster and connect it to DB.
$cluster  = $builder->build();
$session  = $cluster->connect();

// Write a query, switch keyspaces.
$query    = new CqlQuery('SELECT * FROM system.schema_keyspaces');

// Send the query.
$future   = $session->query($query);

// Wait for the query to execute; retrieve the result.
$future->wait();
$result   = $future->getResult();

if (null === $future->getError()) {

	echo "rowCount: {$result->getRowCount()}\n";
	
	while ($result->next()) {
		echo "strategy_options: " . $result->get("strategy_options") . "\n";
	}
	
}

// Boilerplate: close the connection session and perform the cleanup.
$session->close();
$cluster->shutdown();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.