Over a million developers have joined DZone.

Using NuoDB from the PHP Zend Framework

DZone's Guide to

Using NuoDB from the PHP Zend Framework

· Database Zone ·
Free Resource

Download the Altoros NoSQL Performance Benchmark 2018. Compare top NoSQL solutions – Couchbase Server v5.5, MongoDB v3.6, and DataStax Enterprise v6 (Cassandra).

The Zend Framework is an object oriented PHP framework that can be used to construct interactive web applications.  NuoDB supports both Zend Framework version 1 and version 2 .  In this TechBlog article, I will show you how to use NuoDB with both Zend Framework v1 and v2.  I will use the example applications that are provided in the Zend Framework documentation and show you how to make them work with NuoDB.

In this blog post, I am using clean a install of 64-bit Ubuntu desktop 12.04.http://www.ubuntu.com/download/desktop  (note: the commands and paths below may be different on other Linux distributions).

Install Apache2 & PHP

First we need to install Apache2, PHP, and enable the Apache2 rewrite module.  You can do that with the following commands:

$ sudo apt-get install apache2
$ sudo apt-get install libapache2-mod-php5
$ sudo a2enmod rewrite

Install and Configure NuoDB

Download NuoDB: http://www.nuodb.com/download

Install NuoDB and run the quickstart: http://www.nuodb.com/nuodb-online-documentation/tasks/t_InstallConfigLix_inst.html

PHP Information

Before we install the NuoDB PHP PDO Driver, we need to obtain some information about the installed PHP Distribution.  Here is what I see on my machine:

$ php -i | grep "PHP Version"
PHP Version => 5.3.10-1ubuntu3.6
PHP Version => 5.3.10-1ubuntu3.6
$ php -i | grep "Thread Safety"
Thread Safety => disabled
$ php -i | grep "Configuration File"
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
$ php -i | grep "extension_dir"
extension_dir => /usr/lib/php5/20090626 => /usr/lib/php5/20090626

Install and Configure NuoDB PHP PDO Driver

To use NuoDB from 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.

Having obtained the PHP Information above, 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.3.NTS/pdo_nuodb.so /usr/lib/php5/20090626

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 Ubuntu, PHP is configured to scan specific directories for PHP .ini files.  The command line version of PHP scans the /etc/php/cli/conf.d directory.  When PHP is executed from Apache2, PHP is configured to scan the /etc/php5/apache2/conf.d directory.  To add NuoDB to those PHP configurations, we can use that extension statement in a file named nuodb.ini and copy that file to those config directories:

$ echo "extension=pdo_nuodb.so" > /tmp/nuodb.ini
$ sudo cp /tmp/nuodb.ini /etc/php5/cli/conf.d/
$ sudo cp /tmp/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 on the default Apache2 website.  Example:

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

Then open a web browser on the URL:


The PDO section should display “nuodb” in “PDO drivers”:


NuoDB Zend Framework Repository

We have a repository on GitHub that holds the files necessary to support NuoDB with the Zend Framework.  You can download it as follows:

$ cd ~/Downloads
$ wget -O nuodb-php-pdo-zend.tar.gz https://github.com/nuodb/nuodb-php-pdo-zend/tarball/master
$ cd ..
$ tar -xzf ~/Downloads/nuodb-php-pdo-zend.tar.gz
$ mv nuodb-nuodb-php-pdo-zend-* nuodb-php-pdo-zend

Zend Framework v1

There is a Zend Framework v1 quickstart example on the framework.zend.com website.  It is located within the Zend Framework 1 documentation.  The quickstart is virtual guestbook application where web visitors can sign the guestbook.

You should start by downloading Zend Framework v1 from the framework.zend.com website and extract it:

$ cd ~/Downloads
$ wget https://packages.zendframework.com/releases/ZendFramework-1.12.3/ZendFramework-1.12.3.tar.gz
$ cd ..
$ tar -xzf ~/Downloads/ZendFramework-1.12.3.tar.gz

The NuoDB Zend Framework repository contains a file Nuodb.php.  That file is the NuoDB Zend Framework v1 Data Adapter.  You must copy Nuodb.php into your Zend Framework v1 library/Zend/Db/Adapter/Pdo directory:

$ cp ~/nuodb-php-pdo-zend/Nuodb.php ~/ZendFramework-1.12.3/library/Zend/Db/Adapter/Pdo/

Now follow the instructions for the quickstart example:


Or you can extract the completed example from the file ~/nuodb-php-pdo-zend/nuodb_zf1_quickstart.tar.gz.

The quickstart example on the framework.zend.com website uses Sqlite.  It is easy to use NuoDB instead of Sqlite.  When it comes time to configure the db-adapter, use the following command to configure NuoDB instead:

$ zf.sh configure db-adapter 'adapter=PDO_NUODB&host=localhost&username=dba&password=goalie&dbname=test@localhost&schema=guestbook&options.autoQuoteIdentifers=false' production

At this point, start your NuoDB Storage Manager/Transaction Engine on the database test@localhost, then use the following nuosql command to create the schema, table, and data:

$ /opt/nuodb/bin/nuosql test@localhost --user dba --password goalie
SQL> USE guestbook;
SQL> CREATE TABLE guestbook (
 "email" VARCHAR(32) NOT NULL DEFAULT 'noemail@test.com',
 "comment" TEXT NULL,
SQL> INSERT INTO guestbook ("email", "comment", "created") VALUES
 'Hello! Hope you enjoy this sample zf application!',
SQL> INSERT INTO guestbook ("email", "comment", "created") VALUES
 'Baz baz baz, baz baz Baz baz baz - baz baz baz.',

That’s all that is needed.

Running the Zend Framework v1 quickstart

Open web browser to: http://zf1quickstart/guestbook


Sign the guestbook:


Zend Framework v2

There is a Zend Framework v2 tutorial example on the framework.zend.com website.  It is located within the Zend Framework v2 documentation. The tutorial is music album inventory application.

You should start by downloading Zend Framework v2 from the framework.zend.com website and extract it:

$ cd ~/Downloads
$ wget https://packages.zendframework.com/releases/ZendFramework-2.2.1/ZendFramework-2.2.1.tgz
$ cd ..
$ tar -xzf ~/Downloads/ZendFramework-2.2.1.tgz

Now follow the instructions for the ZF2 tutorial example:


Or you can extract the completed example from the file ~/nuodb-php-pdo-zend/nuodb_zf2_tutorial.tar.gz.

In the “Database and modules” section, instead of using MySQL, create the following schema, table, and data in NuoDB:

$ /opt/nuodb/bin/nuosql test@localhost --user dba --password goalie
SQL> CREATE SCHEMA zf2tutorial;
SQL> USE zf2tutorial;
 "id" int NOT NULL generated by default as identity,
 "artist" varchar(100) NOT NULL,
 "title" varchar(100) NOT NULL,
SQL> INSERT INTO "album" ("artist", "title")
 VALUES  ('The  Military  Wives',  'In  My  Dreams');
SQL> INSERT INTO "album" ("artist", "title")
 VALUES  ('Adele',  '21');
SQL> INSERT INTO "album" ("artist", "title")
 VALUES  ('Bruce  Springsteen',  'Wrecking Ball (Deluxe)');
SQL> INSERT INTO "album" ("artist", "title")
 VALUES  ('Lana  Del  Rey',  'Born  To  Die');
SQL> INSERT INTO "album" ("artist", "title")
 VALUES  ('Gotye',  'Making  Mirrors');

Database Configuration

Modify config/autoload/global.php (in the Zend Skeleton root, not inside the Album module) with following code:

 return array(
    'db' => array(
    'driver'         => 'Pdo',
    'dsn'            => 'nuodb:database=test@localhost;schema=zf2tutorial',
    'service_manager' => array(
       'factories' => array(
           'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',

You should put your database credentials in config/autoload/local.php so that they are not in the git repository (as local.php is ignored):

  return array(
     'db' => array(
         'username' => 'dba',
         'password' => 'goalie',

Running the Zend Framework v2 tutorial

Open web browser to: http://zf2-tutorial/album


Add new album

Download the whitepaper, Moving From Relational to NoSQL: How to Get Started. We’ll take you step by step through your first NoSQL project.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}