Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

CodeIgniter - Fired Up on NuoDB

DZone's Guide to

CodeIgniter - Fired Up on NuoDB

· Database Zone ·
Free Resource

Download "Why Your MySQL Needs Redis" and discover how to extend your current MySQL or relational database to a Redis database.

Curator's Note: The content of this article was written by Tom Gates over at the NuoDB Techblog. 

CodeIgniter

CodeIgniter is a powerful PHP framework with a very small footprint.  It is built for PHP coders who need a simple and elegant toolkit to create full-featured web applications.  I will show you how you can use NuoDB to power the CodeIgniter tutorial “News” application. The CodeIgniter website is:

http://ellislab.com/codeigniter

In this blog article, I am using clean install of 64-bit Linux Mint 15. (note: the commands and paths below may be different on other Linux distributions).

Install and Configure NuoDB

We will start by downloading NuoDB then install NuoDB and run the quickstart. To use NuoDB with PHP, you will need to install and configure the NuoDB PHP PDO Driver. The source code is available on GitHub, but you probably won’t need to build it yourself because your NuoDB installation already contains pre-built drivers for PHP 5.3 NTS and PHP 5.4 NTS.

PHP Configuration

The Linux Mint 15 distro uses PHP 5.4.9 NTS. You can see this with the following command:

$ php -i | grep "PHP Version"
PHP Version => 5.4.9-4ubuntu2.1

Next, we can find the location of the PHP extension_dir:

$ php -i | grep extension_dir
extension_dir => /usr/lib/php5/20100525 => /usr/lib/php5/20100525

Install and Configure NuoDB PHP PDO Driver

Having obtained the PHP version and extension_dir, we can copy the correct NuoDB PHP PDO Driver to that extension_dir with the following command:

$ sudo cp /opt/nuodb/drivers/php_pdo/php-5.4.NTS/pdo_nuodb.so /usr/lib/php5/20100525

Next, we need to modify the PHP Configuration to dynamically load the NuoDB PHP PDO Driver. This is done by adding “extension=pdo_nuodb.so” to your PHP initialization files. On Mint 15, PHP is configured to scan specific directories for PHP .ini files. The command line version of PHP scans the /etc/php5/cli/conf.d directory. When PHP is executed from Apache2, PHP is configured to scan /etc/php5/apache2/conf.d directory. To add NuoDB to those PHP configurations, we can use that extension statement in a file named 15-nuodb.ini and copy that file to those config directories:

$ echo "extension=pdo_nuodb.so" > /tmp/15-nuodb.ini
$ sudo cp /tmp/15-nuodb.ini /etc/php5/cli/conf.d/
$ sudo cp /tmp/15-nuodb.ini /etc/php5/apache2/conf.d/
$ sudo /etc/init.d/apache2 restart

Verify Proper Loading of NuoDB PHP PDO Driver

We can verify the proper configuration and loading of the NuoDB PHP PDO Driver by calling the phpinfo() function from a .php file that we can copy to the default Apache2 website. Example:

$ echo "<? phpinfo(); ?>" > /tmp/phpinfo.php
$ sudo cp /tmp/phpinfo.php /var/www/

Then use the web browser with the URL:

http://localhost/phpinfo.php

Download CodeIgniter

You can download CodeIgniter from the ellislab.com website and extract it into /var/www:

$ wget http://ellislab.com/codeigniter/download -O ${HOME}/codeigniter.zip
$ cd /var/www/
$ sudo unzip ${HOME}/codeigniter.zip
$ cd CodeIgniter_2.1.3

CodeIgniter News Tutorial

CodeIgniter has a simple tutorial application which is called “news”.   The instructions for the CodeIgniter News tutorial is on the CodeIgniter website:

http://ellislab.com/codeigniter/user-guide/tutorial/index.html

You should follow the instructions on that website, or if you are lazy, you can download the complete tutorial from the NuoDB website at:  http://nuodb.com/latest/CodeIgniter_NuoDB_tutorial.tar.gz

Using NuoDB

To use NuoDB with CodeIgniter, modify the application/config/database.php to use:

$db['default']['hostname'] = 'nuodb:database=test@localhost;schema=CodeIgniter';
$db['default']['username'] = 'dba';
$db['default']['password'] = 'goalie';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'pdo';

Then start up the NuoDB processes and create a “news” database using the nuosql command prompt:

$ /opt/nuodb/bin/nuosql test@localhost --user dba --password goalie
SQL> create schema CodeIgniter;
SQL> use CodeIgniter;
SQL> CREATE TABLE news (
 "id" int NOT NULL generated by default as identity,
 "title" varchar(128) NOT NULL,
 "slug" varchar(128) NOT NULL,
 "text" text NOT NULL,
 PRIMARY KEY (id) );
SQL> insert into news ("title", "slug", "text") values ('red sox win', 'tgates', 'The red sox win the world series!');
SQL> insert into news ("title", "slug", "text") values ('NuoDB 1.1.1', 'tgates', 'NuoDB version 1.1.1 is now available for download!');
SQL> exit;

Running the News example

Open your web browser to the url:

http://localhost/CodeIgniter_2.1.3/index.php/news

CodeIgniter NuoDB tutorial








Read "Developing Apps Using Active-Active Redis Enterprise" and discover the advantages over other active-actve databases.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}