Zend Server has out-of-the-box support for connectivity to Oracle databases, minimizing the time required for setting up a PHP stack. The built-in support has been limited though. From our point of view it’s just the a size issue. The complete Oracle Instant Client is over 100Mb, which is about half of the whole default Zend Server installation.
The implementation of Oracle OCI in Zend Server 5.1 is based on the Oracle Instant Client Basic Lite version 11.2.0.2, which has support for following connectivity features:
- English error messages
- Unicode, ASCII, and Western European character sets
So far so good. A connection to an Oracle database is easily made with a few pieces of PHP code.
<?php
$conn = oci_connect('username', 'password', 'xxx.xxx.xxx.xxx:1521/instancename');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// connect to the dual table for testing purposes
$stid = oci_parse($conn, 'SELECT * FROM dual');
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
But what if you receive the following error:
ORA-12737: Instant Client Light: unsupported server character set WE8ISO8859P15
What??? Didn’t we have support for Western-European character sets? Isn’t ISO-8859-15 just ISO-8859-1 with Euro sign support and few language specific characters?
So the out-of-the-box solution doesn’t suffice anymore. Tweaking time! On the Zend forums a solution can be found which really works well for Zend Server.
What if you’re running command line scripts that execute PHP commands? The following changes were made on a CentOS x86_64 machine, but any RHEL type should work out.
Download and install the RPM of Oracle Instant Client 11.2.0.2 Basic.
Create a .sh file in your /etc/profile.d directory, in this case we named it ‘oracle-instant-client-zend-server.sh’:
if [ -z $LD_LIBRARY_PATH ];then
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/lib/oracle/11.2/client64/lib:/usr/local/zend/lib
else
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/11.2/client64/lib:/usr/local/zend/lib
fi
export LD_LIBRARY_PATH
export ORACLE_HOME=/usr/lib/oracle/11.2/client64/lib
Set execution rights on the file;
chmod 755 oracle-instant-client-zend-server.sh
Edit your zce.rc file in /etc and the following line as the first line in the file:
. /etc/profile.d/oracle-instant-client-zend-server.sh
And reset your profile settings afterwards:
source /etc/profile
After this stage you should be able to execute scripts from the command line and in Zend Server. But still the tweaking wasn’t over.
The cron deamon won’t pick up the correct libraries because it doesn’t use the same profile settings. To solve this issue one more file has to be edited: /etc/ld.so.conf.d/zend_server.conf
Add the following line before the /usr/lib64 line. Because that is where the liboci8-zend RPM installs the Basic Lite version libraries.
/usr/lib/oracle/11.2/client64/lib
Reset your ldconfig settings by executing:
ldconfig
And you are good to go!