You are viewing bshensky

OMFG! The PECL OCI8 installer enabled PEAR::Oracle as well!

« previous entry | next entry »
May. 30th, 2006 | 02:35 pm
mood: giddygiddy


Wow.  Just wow!  Finally - PHP PEAR DB connecting to Oracle, both easy and without recompiling!

I have spent a dog's age researching how to get my local PHP install to talk to Oracle using PEAR and the OCI8 client stack on my Fedora Core 4 server.  I eventually came to the conclusion that it was just not possible to get OCI8 to work with a RPM(binary)-install of PHP, and I looked toward other means of getting "Web access" to Oracle using different means, including:
  1. mod_owa - Doug McMahon's ultra-cool drop-in replacement for Oracle's mod_plsql that lets me use my own damn Apache install
  2. Easysoft ODBC drivers - Now this gets my goat.  Easysoft provides a free Oracle ODBC driver for Windows but not for Linux!  I guess they don't see Windows as a strategic Oracle server platform, eh?  Anyway, my trial license expired over the weekend, and the ODBC driver stopped working.  Yikes!
  3. Zend Core for Oracle - Zend now offers a separate Oracle-enabled install of their product, but I did not want to run a separate set of PHP binaries!
Today, I found an interesting document on the Oracle Web site that allegedly details how to get the new PECL PDO database drivers for Oracle running on PHP 5 (luckily, I run PHP 5 on my FC4 box).  I read the article, salivating at this item (emphasis mine):
Runtime Extensible. The PDO extension is modular, allowing you to load a driver for your database backend at runtime, without having to recompile or reinstall your entire PHP distribution. For example, the PDO_OCI extension implements the Oracle database API on behalf of the PDO extension.
Sold!  But how do I get PDO installed?  Attempts to do
    $ pear install PDO-alpha
failed on my box.  Besides, don't the FC4 yum libs come with a bunch of prebuilt PEAR RPMS?  I Googled "php peco pdo rpm" and soon discovered that yum could give me what I wanted:
    $ yum install php-pecl-pdo-devel
which, in turn instaled "php-pecl-pdo", all as found here.  Now, make sure there's a new pdo.ini file in /etc/php.d/ - then check to see if there's a PDO entry in phptest()....YES!  Cool!  Halfway there!

Now for the Oracle part...

It stands to reason that if PDO base is installed, all we really need is this alleged PDO OCI "runtime" component, yes?  After more Googling, I realized that the actual PDO OCI libs must be accessible at http://pecl.php.net.  Indeed, the package is there.

So, I took a chance to see if PEAR itself would let me download and install the package, like this:
$ pear install http://pecl.php.net/get/oci8
Amazing!  It prompted me for the location of my ORACLE_HOME.  Chug chug chug, and...It worked:
# pear install http://pecl.php.net/get/oci8
downloading oci8-1.2.1.tgz ...
Starting to download oci8-1.2.1.tgz (67,874 bytes)
.................done: 67,874 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version:         20031224
Zend Module Api No:      20041030
Zend Extension Api No:   220040412
Please provide the path to ORACLE_HOME dir. Use 'instantclient,/path/to/instant/client/lib' if you're compiling against Oracle Instant Client [autodetect] : /home/oracle/product/infra
building in /var/tmp/pear-build-root/oci8-1.2.1
running: /tmp/tmpnd233Y/oci8-1.2.1/configure --with-oci8=/home/oracle/product/infra
.
<snip>
.
Build process completed successfully
Installing '/var/tmp/pear-build-root/install-oci8-1.2.1//usr/lib/php/modules/oci8.so'
install ok: channel://pear.php.net/oci8-1.2.1
Now, the "--with-oci8" I saw therein inspired me.  Where was this new library?  What was it called?  Is it specific to PECL PDO?

# find /usr/lib/php -name \*oci\*
/usr/lib/php/modules/oci8.so
OK, $h!ts and giggles time...let's try this out...add an entry for oci8.so to /etc/php.d/pdo.ini:
; Enable PDO extension module
extension=pdo.so
extension=oci8.so
Restart server.  View phpinfo().

    OCI8 Support: enabled

No way!
  So I pulled together a PEAR DB test page to see if it really works:
<?php
  require_once ( "DB.php" ) ;
  $db = DB::connect ( "oci8://username:password@connectstring" ) ;
  $result = $db->getOne ( "SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') AS XSYSDATE__ FROM DUAL" ) ;
?>
OCI8 DRIVER TEST: TIME IS <?php echo $result ?>
The result:
OCI8 DRIVER TEST: TIME IS 2006-05-30 15:12:07
Alas, it is done.  It appears that the PECL PDO OCI driver install procedure, which promises Oracle connectivity without recompiling PHP, also allows PEAR DB Oracle connections without recompiling either!

I feel better now.

Link | Add to Memories | Share

Comments {2}

Awesome! ... but I have a question

from: anonymous
date: Jun. 23rd, 2006 05:09 pm (UTC)
Link

Great blog entry. Everything works except the part where I have to actually talk to the f'ing database. I want to achieve the php-oracle zen state that you have! If you wouldn't mind answering a quick question for me ...

From phpinfo, do you have --without-pdo in your configure options?

I've read that this causes problems with oci8 if it *is* specified, which it is in the 5.1.4 rpm from RH FC5.

zeroaffinity at
gmail dot
com

Thread

bshensky

Re: Awesome! ... but I have a question

from: bshensky
date: Jun. 26th, 2006 02:07 pm (UTC)
Link

The answer:
I do *not* have *any* mention whatsoever of pdo in the configure options as reported by phpinfo(). Neither "--without-pdo" nor "--with-pdo" are specified. So I guess I'm all clear.

FWIW, my FC4 install included *everything* - so there might have been an FC4 RPM installed that permitted the PDO install (or at least disallowed the denial of a PDO install).

I'm curious...where did you hear the comment about the PDO troubles with the 5.1.4 RPM from FC5?

Hope this helps...

-b

Parent | Thread