View as source file or XML.

Zorba with PHP 5 - Windows Installation

These steps were checked on Windows 7.It should work fine with any PHP 5.X version and any other W32 platform.

Install Apache HTTP Server

Download and install Apache Server from http://httpd.apache.org/download.cgi. You can also get Apache compiled and optimized with Visual Studio VC9 and other modules (like PHP5 module) from Apache Lounge.

Install PHP5

Download and install PHP5 from http://windows.php.net/download/. Remember to download and install according your VC version.PHP will automatically install itself in to your apache server. If you got Apache from Apache Lounge you may need their PHP module version.You can verify your install by adding a file in your htdocs directory with the following code:
<strong>info.php</strong>
<?php
    phpinfo();
?>

Install Zorba

You can install the latest version of Zorba by downloading the most recent binaries, additionaly you can also compile Zorba from source by following Zorba Build Instructions.

Compiling the Zorba PHP Extension

If you are compiling Zorba, you will need also to compile the PHP Wrapper, to do this you besides the Zorba Build Instructions you need to add these three variables to your CMAKE command line:
-D PHP5_BINARY_DIR=[PHP INSTALL]
[PHP INSTALL] is the directory where php.exe is located, i.e. "C:\php"

-D PHP5_INCLUDE_DIR=[PHP INCLUDE DIR]
[PHP INCLUDE DIR] is the directory where the php source is located, i.e. "C:\php-5.3.5"

-D PHP5_LIBRARY=[PHP LIBRARY]
[PHP LIBRARY] is the path where the php5ts.lib is located, this file is usually located in dev directory from the binary php installation, i.e. "C:/php/dev/php5ts.lib"
After adding those lines CMAKE will add automatically the PHP Wrapper project and you will be able to get zorba_api.dll, which is the extension you can use in your php binary installation.

Verify Zorba

Check Zorba is working by command line:
C:\zorba.exe -q '2+1'
<?xml version="1.0" encoding="UTF-8"?>
3

Enable Zorba extension in PHP

Copy Zorba extension zorba_api.dll file into your php extensions directory, this extension is located on: Zorba compiled from sources: [ZORBA BUILD DIRECTORY]\[DEBUG/RELEASE IF VISUAL STUDIO] Zorba installed binaries: [ZORBA INSTALL DIRECTORY]\this file must be copied to your extensions directory that may be:
C:\php\ext\
Modify your php.iniAdd the following line to php.ini extension=zorba_api.dll In your Zorba directory, locate the files zorba_api_wrapper.php and XQueryProcessor.php, copy them it to your include directory from where php can find it, this location is set on your php.ini file with the name <cope>include_path, i.e. ; Windows: "\path1;\path2" include_path = ".;C:\php\include" Restart Apache Http server Refresh your browser with previous info file: http://localhost/info.phpCheck if zorba_api is in the list of php known extensions.

Verify it works

Add the following content in to a file on your htdocs directory:test.php
<html>
<title>Zorba test</title>
<body>
<?php
    // include Zorba API
    require_once 'zorba_api_wrapper.php';
    // create Zorba instance in memory
    $ms = InMemoryStore::getInstance();
    $zorba = Zorba::getInstance($ms);
    try {
        // create and compile query string<
        $queryStr = '1+2';
        $query = $zorba->compileQuery($queryStr);
        // execute query and display result
        $result = $query->execute();
        echo $result;
        // clean up
        $query->destroy();
        $zorba->shutdown();
        InMemoryStore::shutdown($ms);
    } catch (Exception $e) {
        die('ERROR:' . $e->getMessage());
    }
?>
</body>
</html>
Point your browser to http://localhost/test.php and see the result.

Further reading

For more details on how to use Zorba API in PHP go to Building XQuery-powered applications with PHP and Zorba article by Vikram Vaswani.