OS:

Ubuntu 12.4 LTS (x86)

Cassandra 2.0.5

 

安裝 Thrift

$ sudo apt-get install libboost-all-dev php5-dev libpcre3-dev pkg-config g++

$ cd /etc/apt/

$ sudo gedit sources.list

在檔案最後面加上  deb http://debian.datastax.com/community stable main

$ sudo wget -O - http://debian.datastax.com/debian/repo_key | apt-key add -

 

$ sudo apt-get update

$ sudo apt-get install libthrift0 libthrift-dev thrift-compiler

$ sudo ln -s /usr/bin/thrift /usr/local/bin/thrift

 

安裝 YACassandraPDO

$ wget https://github.com/Orange-OpenSource/YACassandraPDO/archive/master.zip

$ unzip master.zip

$ cd YACassandraPDO-master/

$ phpize

$ ./configure

$ make

$ make test

$ make install

$ cd /etc/php5/cli/

$ sudo gedit php.ini

在檔案後面加上 extension=pdo_cassandra.so

$ /etc/init.d/mysql restart

 

測試是否安裝成功 ٩(๑•̀ω•́๑)۶

<?php

$dsn = 'cassandra:host=127.0.0.1;port=9160;cqlversion=3.0.0';

$username = "";
$password = "";

$db = new PDO($dsn, $username, $password);

$db->exec ("CREATE KEYSPACE yapdo WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor': 1}");
$db->exec ("USE yapdo;");


$db->exec("CREATE TABLE test (id int PRIMARY KEY, map_test map<varchar, int>);");
$db->exec("INSERT INTO test (id, map_test) VALUES (1, {'val1': 2, 'val2': 1, 'val3': 3});");
print_r($db->query('SELECT * FROM test;')->fetchObject());

 

相關文章