The starting point for this article, is being able to write PHP using OCI (Oracle Call Interface) - to connect, and fetch data from our Oracle XE installation. For this, I will use Zend Core for Oracle.
"Zend Core is a fully tested and enhanced version of the open source PHP. It is packaged to make the software installation easier and faster with instant PHP setup. Zend Core uniquely delivers a seamless out-of-the-box experience by bundling all the necessary drivers and third party libraries to work with the database or platform of your choice. "
If you don't yet, have an Oracle Database XE, installed on your system Read about it here. To get everything running, you need a few things installed.
1. PHP, a widely used scripting language - can be downloaded from here.
2. Zend Core for Oracle can be downloaded here. (app. 60 Meg.) Zend core supports Apache 1.3 and 2.0.xx
3. Apache server can be downloaded from here.
Zend Core Installation
Once Zend Core have been downloaded, the installation can start. Click on the downloaded archive and the installation wizard starts; You system configuration, is checked - to see which apache version you are running - and accordingly, Zend will be configured. However you can run Zend with use of CGI only - but for this installation we stick with Apache. To access the administration console - you are prompted for a password; I set mine to "MANAGER". Once installation have copied files, configured apache etc. your system needs to be restarted. Please note - your httpd.conf file have been changed - and the original file is renamed to httpd.conf.zend-core.bak.
After a restart - I take a look at the httpd.conf file;
LoadModule php5_module "C:/Programmer/Zend/Core For Oracle/bin/php5apache2.dll"
PHPIniDir "C:/Programmer/Zend/Core For Oracle/etc"
AddType application/x-httpd-php .php
<Location /ZendCore>
AllowOverride none
Order deny,allow
Allow from all
</Location>
Alias /ZendCore "C:/Programmer/Zend/Core For Oracle/GUI"
In my original file I was using AddType - which now have been commented out
# AddType application/x-httpd-php .php .phtml
# Action application/x-httpd-php "/php/php.exe"
And so have my ScriptAlias directive.
#ScriptAlias /php/ "c:/u01/php/"
The changes made by the installation wizard are pretty harmless - however please note the load module - is trying to load a PHP version 5 DLL - so having PHP 5 on your system - is a very good idea. PHP and latest versions can be downloaded here.
If you wonder about your current versions - of PHP, start a DOS prompt and issue a php -v
Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\K. Birch-Johansen>php -v
PHP 5.0.5 (cli) (built: Feb 14 2006 20:37:32) Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.5, Copyright (c) 1998-2004 Zend Technologies
with Zend Core v1, Copyright (c) 1998-2005, by Zend Technologies
with Zend Extension Manager v1.0.7, Copyright (c) 2003-2005, by Zend Technologies
with Zend Optimizer v2.6.2, Copyright (c) 1998-2006, by Zend Technologies
with Zend Debugger v5.1.0, Copyright (c) 1999-2006, by Zend Technologies
Zend Core's Administration console
Start your favorite browser, and enter the following URL in the address line http://localhost/ZendCore/
You should now see the login page to Zend Core's administration console. Enter the password, you set during installation. Mine was MANAGER.
The User interface (UI) - is very easy to work with. One thing you notice right away - is that if you have struggled with editing of your PHP.ini file from time to time - well here Zend have everything needed - gathered here, so you are just a few clicks away from changes to be in effect. Please note that making changes, requires to restart your Apache (unless you are running PHP/CGI) - but why not do it from within the administration ? Look to your top right -> Restart Server - its good and easy - and i don't have to go to the system tray, apache console, and back again :)
Zend core comes with the most common extensions -again its so easy - have you struggled with getting picture manipulation to work with PHP and GD library ? you are just 2 clicks away.
The administration also provides you with options to monitor and benchmark your scripts. To try benchmarking, you enter an URL, and an output will be produced containing, time, memory etc.
All in All - the administration part of Zend Core, gives you a great level of abstraction - and I think its a very pleasant interface - which wants me to come back.
PHP/OCI test
Lets try it out - In your DOCUMENT_ROOT, create a new file, and call it oratest.php. We want with this exercise - to test if we can reach our Oracle XE installation.
Make sure that your Oracle services are up and running (to check use services.msc, look for Oracle).
If you remember, during the XE installation - we noticed that - the installation did provide us with several default accounts. One of those where the user HR. You should read the article - in order for you to unlock the HR account before going on.
<?php
$conn = oci_connect('HR', 'HR', 'XE');
if (!$conn) {
$e = oci_error();
print htmlentities($e['message']);
exit;
}
$query = 'SELECT * FROM employees';
$sth = oci_parse($conn, $query);
if (!$sth) {
$e = oci_error($conn);
print htmlentities($e['message']);
exit;
}
$results = oci_execute($sth, OCI_DEFAULT);
if (!$results) {
$e = oci_error($sth);
print htmlentities($e['message']);
exit;
}
print '<table style="border: 1px solid gray;">';
while ($row = oci_fetch_array($sth, OCI_RETURN_NULLS)) {
print '<tr>';
foreach ($row as $item) {
print '<td style="border: 1px solid gray; padding:3px 5px 3px 5px;">'.($item?htmlentities($item):' ').'</td>';
}
print '</tr>';
}
print '</table>';
oci_close($conn);
?>
Below you can see the output. I am connecting to my XE instance as user HR, and selecting data from the table EMPLOYEES. The XE descriptor, is described in my TNSNAMES.ORA file.

The output, does not look real good - and in my next article PHP/OCI and Apache - I will work a little more on that.
Security and changes to the default installation
If you have not all ready done so - maybe its a good time now. If for some reason Apache fails loading your PHP code - the code are shown as plain text - which is not so cool. However you can edit your httpd.conf file and add the following directive.
<IfModule !mod_php5.c>
<Files ~ "\.php>
Order allow,deny
Deny from all
</Files>
</IfModule>
<Files ~ "\.inc>
Order allow,deny
Deny from all
</Files>
You might also consider to change expose_php
Configuration>PHP>Language Options to off.
There is a lot of other things you should consider. So what am I saying. Well what I am saying is just; you should bare in mind that a default installation, is a default installation. If you are running a web service - or something else - you should plan your installation, consider effects, plan versions etc. Also each version of a given piece of software - tends to have new features and changes to default values when it hits the market in a brand new version.
Conclusion
If you have follow the article - you now have a strong development environment on your computer. Zend Core and Oracle XE are stable, reliable and supported versions for your PHP development. I have far from, covered all aspects - however this will get you started. In later articles I will cover more on development, test, tools. I wish you goo luck and happy programming.
Further information
Step by Step installation (Linux) by Christoffer Jones and Alison Holloway http://www.oracle.com/technology/tech/php/htdocs/php-oracle-tutorial.html?rssid=rss_otn_news
The Oracle+PHP cookbook Explore a broad range of HowTos for leveraging Oracle's PL/SQL APIs in PHP applications.
Oracle PHP Center Oracel's PHP development center