Archive for February, 2015

CodeIgniter & TokuMX

February 4, 2015 Leave a comment

CodeIgniter is a lightweight PHP framework that can help you to develop Web Application. TokuMX is a drop-in replacement for MongoDB, that support transaction.

You can download codeigniter from here, and TokuMX from here . For more information about how to install TokuMX, you can read TokuMX documentation from GitHub here.

To Make Web Application can connect to Mongo Instance, you need to install PHP extension for mongo. To Install in Centos or Redhat environment, run command :

pecl install mongo

and add to /etc/php.ini

Restart Web Service

service httpd restart

Download codeigniter-mongo-library from here .

Here’s simple code example how to use codeigniter-mongo-library to perform CRUD operation.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller
  // Insert Operation
  public function mongo_insert_test()      
     for($i=0;$i<25;$i++) {
            ->insert("testData", array("x" => $i, "y" => 25-$i ));

  // Select Operation 
  public function mongo_select_test()
     $mongo_data = $this->cimongo->get("testData");
     foreach($mongo_data->result_array() as $row) {
        echo sprintf('x:%d,y:%d <br>',$row['x'],$row['y']);
  // Update Operation
  public function mongo_update_test()
     $result = $this->cimongo->where(array("x" => 24 ))
                    ->set(array("x" => 25 ))->update("testData");
     echo $result

  // Delete Operation
  public function mongo_delete_test()
     $result = $this->cimongo->where(array("x" => 25 ))
     echo $result;




Categories: Database, Mongo, PHP, Programming