by Rodolfo Ochoa, May 24th, 2011
These steps were checked on Windows 7. It should work fine with any PHP 5.X version and any other W32 platform.
Download and install Apache Server from http://httpd.apache.org/download.cgi for VC6. For apache compiled with VC9 download it from http://apachelounge.com/.
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.
You can verify your install by adding a file in your htdocs directory with the following code:
<strong>info.php</strong> <?php phpinfo(); ?>
Get Zorba sources and follow Build Instructions.
In order to compile the PHP Wrapper you need first to follow the steps to compile Zorba, but before compiling, you need to add three variables to the CMAKE command line:
-D PHP5_BINARY_DIR=... Specify the directory where php.exe is located, i.e. "C:\php" -D PHP5_INCLUDE_DIR=... Specify the directory where the php source is located, i.e. "C:\php-5.3.5" -D PHP5_LIBRARY=... Specify with normal slash 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.
Check Zorba is working by command line:
C:\zorba.exe -q '2+1' <?xml version="1.0" encoding="UTF-8"?> 3
Copy Zorba extension zorba_api.dll file into your php extensions directory, i.e.
C:\php\ext\
Modify your php.ini
Add the following line to php.ini
php.ini extension=zorba_api.dll In your Zorba directory, locate the file zorba_api_wrapper.php and copy it to an include directory from where php can find it from your setting include_path, i.e.
php.ini ; Windows: "\path1;\path2" include_path = ".;C:\php\include" Restart Apache Http server
Refresh your browser with previous info file: http://localhost/info.php
Check if zorba_api is in the list of php known extensions.
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.
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.