Dear Wiki user, You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.
The following page has been changed by wadearnold: http://wiki.apache.org/cassandra/ClientExamples ------------------------------------------------------------------------------ The most common way to access Cassandra is via the [http://incubator.apache.org/thrift/ Thrift] interface. == PHP == + Cassandra 0.4 Preview + + {{{ + <?php + $GLOBALS['THRIFT_ROOT'] = '/usr/share/php/Thrift'; + + require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/Cassandra.php'; + require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php'; + require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php'; + require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php'; + require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php'; + + try { + // Make a connection to the Thrift interface to Cassandra + $socket = new TSocket('127.0.0.1', 9160); + $transport = new TBufferedTransport($socket, 1024, 1024); + $protocol = new TBinaryProtocol($transport); + $client = new CassandraClient($protocol); + $transport->open(); + + + /* Insert some data into base attributes */ + + // Table name specified in storage=conf.xml + $tableName = 'users'; + + // reference to specific User id + $keyUserId = "1"; + + // Constructing the column path that we are adding information into. + $columnPath = new cassandra_ColumnPath(); + $columnPath->column_family = 'base_attributes'; + $columnPath->super_column = null; + $columnPath->column = 'email'; + + // Timestamp for update + $timestamp = time(); + + // block_for specifies how many nodes need to process the update before you call it a success. + //0=async insert(minimal), 1-N(nodes) number of nodes to commit + $block_for = 0; + + // Add the value to be written to the table, User Key, and path. + $value = "[email protected]"; + $client->insert($tableName, $keyUserId, $columnPath, $value, $timestamp, $block_for); + + // Add a new column path to be altered. + $columnPath->column = 'age'; + $columnPath= new cassandra_ColumnPath($columnPathArgs); + //Get a current timestamp + $timestamp = time(); + // Update the value to be inserted for the updated column Path + $value = "24"; + $client->insert($tableName, $keyUserId, $columnPath, $value, $timestamp, $block_for); + + /* Query for data */ + + // Specify what Column Family to query against. + $columnParent = new cassandra_ColumnParent(); + $columnParent->column_family = "base_attributes"; + $columnParent->super_column = null; + + // Start less than zero gets all results + $start = -1; + // Specify a range that you want to get from. -1 ignores the range. + $end = -1; + // Controls the sorting of the results. Booleand value + $is_ascending = true; + // Count is used like an SQL limit for creating page-able results. + $count = 10; + + // Issue the Query + $result = $client->get_slice($tableName, $keyUserId, $columnParent, $start, $end, $is_ascending , $count); + + + print_r($result); + $transport->close(); + + } catch (TException $tx) { + print 'TException: '.$tx->why. ' Error: '.$tx->getMessage() . "\n"; + } + ?> + }}} + + Cassandra <= 0.3 + {{{ <?php
