PHPackages                             sachoo/phalcon-cassandra - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. sachoo/phalcon-cassandra

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

sachoo/phalcon-cassandra
========================

Cassandra library for Phalcon

1.3.2(8y ago)1016.8k1[4 issues](https://github.com/SachaMorard/phalcon-cassandra/issues)MITPHPPHP &gt;=5.5

Since Mar 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/SachaMorard/phalcon-cassandra)[ Packagist](https://packagist.org/packages/sachoo/phalcon-cassandra)[ RSS](/packages/sachoo-phalcon-cassandra/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Cassandra library for Phalcon
=============================

[](#cassandra-library-for-phalcon)

[![status](https://camo.githubusercontent.com/90e7b3ecad4fb3497391caaff5237891f26a5ae0c99e75fc6c51cb05e1766738/68747470733a2f2f6170692e7472617669732d63692e6f72672f53616368614d6f726172642f7068616c636f6e2d63617373616e6472612e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/90e7b3ecad4fb3497391caaff5237891f26a5ae0c99e75fc6c51cb05e1766738/68747470733a2f2f6170692e7472617669732d63692e6f72672f53616368614d6f726172642f7068616c636f6e2d63617373616e6472612e7376673f6272616e63683d6d6173746572)

Requirements
------------

[](#requirements)

- PHP &gt;= 5.3
- Cassandra php driver
- Phalcon &gt;= 3.0

Cassandra php driver () hasn't appropriate version number. The only version number available is for C/C++ driver version (wich is not the version of the extension itself). Because of it, version of this library follow the cassandra php-driver real version.

If you need to use cassandra php-driver v1.2.2, please install our library at 1.2.2 Follow the exact same logic for other available versions.

Installing via Composer
-----------------------

[](#installing-via-composer)

Install composer in a common location or in your project:

```
curl -s http://getcomposer.org/installer | php
```

Create the composer.json file as follows:

```
{
    "require-dev": {
        "sachoo/phalcon-cassandra": "1.3.0"
    }
}
```

Run the composer installer:

```
php composer.phar install
```

How to use
----------

[](#how-to-use)

First of all you have to add and define some conf in your phalcon config file

```
return new \Phalcon\Config([
    'cassandra' => [
        'adapter' => 'Cassandra',
        'hosts' => [ 'localhost'],
        'keyspace' => 'lobs',
        'consistency' => 'ONE', // Infos here \cassandra\ConsistencyLevel
        'retryPolicies' => 'DefaultPolicy',
    ]
]);
```

Then, you have to declare Cassandra service in your dependency injector :

```
/**
 * This service returns a Cassandra database
 */
$di->setShared('dbCassandra', function () {
    $config = $this->getConfig();
    $connection = new \Phalcon\Db\Adapter\Cassandra($config->cassandra->toArray());
    return $connection;
});
```

IMPORTANT, if you are using mysql too, you have to change the name of mysql service in **dbMysql**. For exemple:

```
$di->setShared('dbMysql', function () {
    $config = $this->getConfig();
    $params = [
        'host' => $config->mysql->host,
        'port' => isset($config->mysql->port) ? $config->mysql->port : 3306,
        'username' => $config->mysql->username,
        'password' => $config->mysql->password,
        'dbname' => $config->mysql->dbname,
        'charset' => $config->mysql->charset
    ];
    return new \Phalcon\Db\Adapter\Pdo\Mysql($params);
});
```

Then, you just have to declare the correct database service to your models in @Source annotation. For exemple:

```
