You are here

NuoDB for PHP

I have written a NuoDB database driver for the PHP Programming language.  The database driver conforms to the PHP Data Objects (PDO) extension API.  In this article, I’ll show you how to install, configure, and use the NuoDB PHP PDO Driver.

  The instructions below are for Windows, but other NuoDB platforms are installed and configured in a similar way.


Pre-requisite 1: Installing PHP

Starting from a Windows machine, you can obtain a binary distribution of PHP from  In this example, I download PHP 5.4.14 VC9 x86 Thread Safe version of PHP (


Then I unzip into the C:\php directory.

Next I add C:\php to the end of PATH environment variable (Start -> Control Panel -> System -> Advanced -> Environment Variables -> System Variables -> Variable: Path).  For example:



Pre-requisite 2: Install and Configure NuoDB

At this point, check that everything is setup correctly by using nuosql  to look at the sample Hockey database:

C:\> nuosql test@localhost –user dba –password goalie –schema HOCKEY



Pre-requisite 3: Install the NuoDB PHP PDO Driver

The source code for the NuoDB PHP PDO Driver is available on GitHub, but you won’t need to build it yourself because pre-built versions of the NuoDB PHP PDO Driver are included in your NuoDB installation. You can find them in drivers\php_pdo directory of your NuoDB installation.  Example:




That directory contains two subdirectories: vc9 and vc10. Use the version that matches the Microsoft Visual C++ compiler version of your PHP executable.  You can find the version of Microsoft Visual C++ compiler that was used to build PHP by using the command php –I | findstr Compiler. For example:




Next, find the location of the extension directory that is used by PHP.  You can do that with the command php –I | findstr extension_dir. For example:



Now that you have determined the version of the Visual C++ compiler and the extension_dir, you can copy the appropriate NuoDB PHP PDO Driver version to that extension_dir.  The NuoDB PHP PDO Driver is a Windows DLL with the namephp_pdo_nuodb.dll.  For example:



Now that you have copied the NuoDB PHP PDO Driver to your PHP extension directory, you need to modify your PHP configuration to automatically load the NuoDB PHP PDO Driver when PHP runs.  Do this by adding the following line to your php.ini file:


For example:




You can use the command php -i | findstr PDO to verify that the NuoDB PHP PDO driver is loading correctly.  You should see the following output:



Using the PDO driver

Now you can run the example.php script to display information from the example “hockey” database.  Example execution output:



Let’s look at an sample application that uses a prepared statement:

try {
$db = new PDO(“nuodb:database=test@localhost;schema=Hockey”, “dba”, “goalie”) or die;
$number = 12;
$sql = “select * from HOCKEY where NUMBER <:number”;
$stmt = $db->prepare($sql);
$stmt->bindParam(‘:number’, $number, PDO::PARAM_INT);
$result = $stmt->fetchAll();
foreach ($result as $row) {
echo “NUMBER=” . $row["NUMBER"] . ” NAME=” . $row["NAME"] . “\n”;
$db = NULL;
} catch(PDOException $e) {
echo $e->getMessage();
} $db = NULL;
echo “done\n”;


The PDO connection is formed by the statement:

$db = new PDO(“nuodb:database=test@localhost;schema=Hockey”, “dba”, “goalie”)




At this point, you can use the NuoDB PHP PDO Driver just like any other PHP PDO Database Driver.

I plan to cover the following in future blog posts:

  • Using NuoDB instead of MySQL in a LAMP stack.
  • Using NuoDB with the PHP Zend Framework.
  • Building the NuoDB PHP PDO Driver from GitHub.

Add new comment