오라클 8 함수

  • authorbibaram
  • 23 January 2006, 22:39:06

LXXVII. 오라클 8 함수

이 함수들을 통해 오라클 8과 오라클 7 데이터베이스를 연동하여 사용한다. Oracle8 Call-Interface (OCI8)를 사용하며, 이 함수들을 사용하려면 오라클8 클라이언트 라이브러리(Oracle8 client libraries)가 필요하다.

이 함수는 표준 오라클 함수보다 유연하다. PHP의 전역 변수와 지역 변수들의 오라클 위치보유자(Oracle placeholder) 로의 연계(binding), full LOB, FILE, ROWID를 지원하며, user-supplied define variable을 사용할 수 있도록 해 준다.

이 함수를 사용하기 전에 오라클 계정과 웹 데몬 계정에 유효한 오라클 환경변수를 적용했는지 확인해야한다. 적용시킬 환경변수:

  • ORACLE_HOME

  • ORACLE_SID

  • LD_PRELOAD

  • LD_LIBRARY_PATH

  • NLS_LANG

  • ORA_NLS33

웹서버 계정으로 위 환경변수를 적용한후에, 웹서버 계정(nobody, www)을 오라클 그룹에 추가했는지 확인해야 한다.

웹서버가 시작하지 않거나 시작시 제대로 작동하지 않으면: 아파치가 pthread 라이브러리에 링크되어있는지 체크하라:

# ldd /www/apache/bin/httpd 
    libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000)
    libm.so.6 => /lib/libm.so.6 (0x4002f000)
    libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000)
    libdl.so.2 => /lib/libdl.so.2 (0x4007a000)
    libc.so.6 => /lib/libc.so.6 (0x4007e000)
    /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

libpthread가 보이지 않으면 아파치를 다시 설치해야한다 :

# cd /usr/src/apache_1.3.xx
# make clean
# LIBS=-lpthread ./config.status
# make
# make install

예 1. OCI Hints

<?php
// by sergo@bacup.ru

// Use option: OCI_DEFAULT for execute command to delay execution
OCIExecute($stmt, OCI_DEFAULT
);

// for retrieve data use (after fetch):

$result = OCIResult($stmt, $n
);
if (
is_object ($result)) $result = $result->load
();

// For INSERT or UPDATE statement use:

$sql =
"insert into table (field1, field2) values (field1 = 'value',
 field2 = empty_clob()) returning field2 into :field2"
;
OCIParse($conn, $sql
);
$clob = OCINewDescriptor($conn, OCI_D_LOB
);
OCIBindByName ($stmt, ":field2", &amp;$clob, -1, OCI_B_CLOB
);
OCIExecute($stmt, OCI_DEFAULT
);
$clob->save ("some text"
);
OCICommit($conn
);

?&
gt;

커맨드 라인(command-line)에서의 사용 방식과 동일하게 내장 프로시저(stored procedures)를 사용할 수 있다.

예 2. 내장 프로시저(Stored Procedures) 사용하기

<?php
// by webmaster@remoterealty.com
$sth = OCIParse ( $dbh,
"begin sp_newaddress( :address_id, '$firstname',
 '$lastname', '$company', '$address1', '$address2', '$city', '$state',
 '$postalcode', '$country', :error_code );end;"
);

// This calls stored procedure sp_newaddress, with :address_id being an
// in/out variable and :error_code being an out variable.
// Then you do the binding:

  
OCIBindByName ( $sth, ":address_id", $addr_id, 10
);
  
OCIBindByName ( $sth, ":error_code", $errorcode, 10
);
  
OCIExecute ( $sth
);

?>

차례
oci_bind_by_name --  Binds the PHP variable to the Oracle placeholder
oci_cancel -- Cancels reading from cursor
oci_close -- Closes Oracle connection
collection->append -- Appends an object to the collection
collection->assign -- Assigns a value to the collection from another existing collection
collection->assignElem -- Assigns a value to the element of the collection
collection->getElem -- Returns value of the element
collection->max -- Gets the maximum number of elements in the collection
collection->size -- Returns size of the collection
collection->trim -- Trims elements from the end of the collection
oci_commit -- Commits outstanding statements
oci_connect -- Establishes a connection to Oracle server
oci_define_by_name --  Uses a PHP variable for the define-step during a SELECT
oci_error -- Returns the last error found
oci_execute -- Executes a statement
oci_fetch_all -- Fetches all rows of result data into an array
oci_fetch_array -- Returns the next row from the result data as an associative or numeric array, or both
oci_fetch_assoc -- Returns the next row from the result data as an associative array
oci_fetch_object -- Returns the next row from the result data as an object
oci_fetch_row -- Returns the next row from the result data as a numeric array
oci_fetch -- Fetches the next row into result-buffer
oci_field_is_null -- Checks if the field is NULL
oci_field_name -- Returns the name of a field from the statement
oci_field_precision -- Tell the precision of a field
oci_field_scale -- Tell the scale of the field
oci_field_size -- Returns field's size
oci_field_type_raw -- Tell the raw Oracle data type of the field
oci_field_type -- Returns field's data type
collection->free -- Frees resources associated with collection object
descriptor->free -- Frees resources associated with descriptor
oci_free_statement --  Frees all resources associated with statement or cursor
oci_internal_debug -- Enables or disables internal debug output
lob->append -- Appends data from the large object to another large object
lob->close -- Closes LOB descriptor
oci_lob_copy -- Copies large object
lob->eof -- Tests for end-of-file on a large object's descriptor
lob->erase -- Erases a specified portion of the internal LOB data
lob->export -- Exports LOB's contents to a file
lob->flush -- Flushes/writes buffer of the LOB to the server
lob->import -- Imports file data to the LOB
oci_lob_is_equal -- Compares two LOB/FILE locators for equality
lob->load -- Returns large object's contents
lob->read -- Reads part of large object
lob->rewind -- Moves the internal pointer to the beginning of the large object
lob->save -- Saves data to the large object
lob->seek -- Sets the internal pointer of the large object
lob->size -- Returns size of large object
lob->tell -- Returns current position of internal pointer of large object
lob->truncate -- Truncates large object
lob->writeTemporary -- Writes temporary large object
lob->write -- Writes data to the large object
oci_new_collection -- Allocates new collection object
oci_new_connect -- Establishes a new connection to the Oracle server
oci_new_cursor -- Allocates and returns a new cursor (statement handle)
oci_new_descriptor -- Initializes a new empty LOB or FILE descriptor
oci_num_fields --  Returns the number of result columns in a statement
oci_num_rows -- Returns number of rows affected during statement execution
oci_parse -- Prepares Oracle statement for execution
oci_password_change -- Changes password of Oracle's user
oci_pconnect -- Connect to an Oracle database using a persistent connection
oci_result -- Returns field's value from the fetched row
oci_rollback -- Rolls back outstanding transaction
oci_server_version -- Returns server version
oci_set_prefetch -- Sets number of rows to be prefetched
oci_statement_type -- Returns the type of an OCI statement
OCIBindByName --  오라클 위치보유자(Placeholder)를 PHP 변수에 연계(bind)시킨다.
OCICancel -- 커서로부터 읽기를 취소한다
ocicloselob -- Closes lob descriptor
ocicollappend -- Append an object to the collection
ocicollassign -- Assign a collection from another existing collection
ocicollassignelem -- Assign element val to collection at index ndx
ocicollgetelem -- Retrieve the value at collection index ndx
ocicollmax --  Return the max value of a collection. For a varray this is the maximum length of the array
ocicollsize -- Return the size of a collection
ocicolltrim -- Trim num elements from the end of a collection
OCIColumnIsNULL -- 결과 컬럼이 널(NULL)인지 테스트한다
OCIColumnName -- 컬럼의 이름을 리턴한다.
ocicolumnprecision -- Tell the precision of a column
ocicolumnscale -- Tell the scale of a column
OCIColumnSize -- 결과 컬럼 사이즈를 리턴한다
OCIColumnType -- 컬럼의 데이터 타입을 리턴한다.
ocicolumntyperaw -- Tell the raw oracle data type of a column
OCICommit -- 미결정된 트랜잭션을 커밋시킨다.
OCIDefineByName --  한 SELECT 구문사용시 정의단계(define-step)를 위한 PHP 변수를 할당한다.
OCIError -- stmt|conn|global의 제일 마지막 에러를 리턴한다. 아무 에러도 없었다면 FALSE를 리턴한다.
OCIExecute -- SQL 구문(Statement)을 수행한다.
OCIFetch -- 결과 버퍼(result-buffer)로 다음 열을 페치한다
OCIFetchInto -- 결과 배열(result-array)에 다음 열을 페치한다
OCIFetchStatement -- 배열에 모든 열의 결과 값을 페치한다.
ocifreecollection -- Deletes collection object
OCIFreeCursor --  커서(cursor)에 연관된 모든 자원을 해제한다.
OCIFreeDesc -- 큰 객체(large object) descriptor를 삭제한다.
OCIFreeStatement --  구문(statement)에 연관된 모든 자원을 해제한다.
lob->getBuffering -- Returns current state of buffering for large object
OCIInternalDebug --  내부 디버그 출력을 활성화 시키거나, 비활성화 시킨다. 기본값으로 비활성화 되어있다.
ociloadlob -- Loads a large object
OCILogOff -- 오라클로부터 접속을 해제한다.
OCILogon -- 오라클 데이터베이스에 접속한다.
ocinewcollection -- Initialize a new collection
OCINewCursor --  새로운 커서(구문 핸들)를 리턴한다 - ref-cursor를 연계하기위함.
OCINewDescriptor --  LOB/FILE의 비어있는 새로운 descriptor를 초기화한다 (LOB 이 기본값이다)
OCINLogon -- 오라클 데이터베이스에 접속하고 새로운 접속을 이용해서 로그온한다. 새로운 세션(session)을 넘겨준다.
OCINumCols --  구문 결과값의 컬럼의 갯수를 리턴한다
OCIParse -- 질의(query)를 해석하고 구문(statement)를 리턴한다
OCIPLogon -- 오라클 데이터베이스에 접속하고 영속적 DB 접속 (persistant connection) 을 이용해서 로그온한다. 또다른 새로운 세션(session)을 넘겨준다.
OCIResult -- 페치된 열의 컬럼 값을 리턴한다
OCIRollback -- 미결정된 트랜잭션을 롤백한다.
OCIRowCount -- 적용되어진 열의 갯수를 가져온다
ocisavelob -- Saves a large object
ocisavelobfile -- Saves a large object file
ociserverversion -- Return a string containing server version information
lob->setBuffering -- Changes current state of buffering for large object
OCISetPrefetch -- 사용할 열의 갯수를 설정한다
OCIStatementType -- OCI 구문(statement)의 타입을 리턴한다.
ociwritelobtofile -- Saves a large object file
ociwritetemporarylob -- Writes temporary blob


add a note add a note User Contributed Notes
오라클 8 함수
cjbj at hotmail dot com
19-Jan-2006 11:09
PHP 5.1.2 was the first PHP release to ship the "re-factored" OCI8 1.1 driver.

The configuration options for the re-factored driver have changed, particularly for building with Oracle Instant Client. Some older articles and documentation are now obsolete.  Run ./configure --help to see the new syntax.

User's of PHP prior to 5.1.2 can install the re-factored driver from
http://pecl.php.net/package/oci8 or http://pecl4win.php.net/ext.php/php_oci8.dll
wes9999 at myfastmail dot com
18-Jan-2006 12:19
If you're compiling php 5.1.2, and using the oracle instant client, the appropriate configure option is:
--with-oci8=instantclient,/path/to/instantclient/libs

which is a change from the configure option for php 5.1.1, which was:
--with-oci8-instant-client=/path/to/instantclient/libs

If you use the old one with php 5.1.2, it just silently ignores this option and the resulting php build doesn't have oracle support.
scoop at subindie dot com
26-Oct-2005 04:27
Regarding compiling with the recently updated OCI8 Extension (http://pecl.php.net/package/oci8).

I ran into problems when statically compiling, such as numerous "undefined reference to `zif_oci_***'" errors.  Since I likely won't be the only one to run into this problem, here's some helpful hints:

If you've previously compiled your php installation, first: make clean

Then replace the existing php-x.x.x/ext/oci8 directory with the latest package from:
http://pecl.php.net/package/oci8

./buildconf --force
./config ..
make
jistanidiot at gmail dot com
16-Sep-2005 11:07
On RHEL for PHP4 or 5...

For Oracle 9i before you compile PHP but after you install Oracle, you need to make the following symlinks:

ln -s $ORACLE_HOME/rdbms/public/nzerror.h  $ORACLE_HOME/rdbms/demo/nzerror.h

ln -s $ORACLE_HOME/rdbms/public/nzt.h $ORACLE_HOME/rdbms/demo/nzt.h

ln -s $ORACLE_HOME/rdbms/public/ociextp.h $ORACLE_HOME/rdbms/demo/ociextp.h

ln -s $ORACLE_HOME/lib/libclntsh.so.9.0 $ORACLE_HOME/lib/libclntsh.so.8.0

ln -s $ORACLE_HOME/oui/bin/linux/libcdlntsh.so.9.0
$ORACLE_HOME/oui/bin/linux/libcdlntsh.so.8.0

With 10g you need to make the first three and then this one:
ln -s $ORACLE_HOME/lib/libclntsh.so.10.0 $ORACLE_HOME/lib/libclntsh.so.8.0
denis dot delamarre at chu-rennes dot fr
10-Jun-2005 01:00
php5 + Apache 2 + solaris 2.10 + oracle9i (64bits)

'./configure' '--with-oracle=/prod/dba/oraeve/ora9i' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-zlib' '--with-gd' '--without-mysql' '--with-oci8=/prod/dba/oraeve/ora9i'

fail with :
ld: fatal : fichier libclntsh.so : wrong elf class : ELFCLASS64

the solution is between ./configure and make command to edit Makefile and replace /ora9i/lib  with  /ora9i/lib32

all it's ok
MSapp
06-Jun-2005 09:48
Problems compiling 5.0.4 with Oracle Instant Client 10? (i.e. cannot find -lirc)

Remove the "-lirc" from sdk/demo/sysliblist and rerun configure.
darkstar_ae at hotmail dot com
26-Apr-2005 01:39
When fetching associative arrays, use uppercase string indices. It appears the PHP OCI Library is less lenient with the field names returned by Oracle.

e.g.

echo $row['field1']; // This won't return anything.

as opposed to:

echo $row['FIELD1'];
kucerar at hhmi dot org
23-Feb-2005 11:29
Great Solaris patch!  Finally built.  Here's some tips on connecting:

Just made this on solaris8 32bit, actually works.

1) put everything in one directory
2) unsetenv ORACLE_HOME
3) set the env vars LD_LIBRARY_PATH and SQLPATH and TNS_ADMIN(if you have it) to that directory.
4) use one of the other easy connection notations here

http://www.oracle.com/technology/
docs/tech/sql_plus/10102/readme_ic.htm

These env vars worked when put at the top of apachectl script as well.

To build you may have to fake it out with an ORACLE_HOME var,  but unset it later.  You may also have to fake out the build by putting header files where it is looking for them,  e.g. in the rdbms/demo directory or some such other place.

When running though,  make sure you have only the files required in only one directory.

Oracle has not put up a link to the 32bit solaris sqlplus--you have to guess it--it's there though:

http://download.oracle.com/otn/solaris/instantclient/
instantclient-sqlplus-solaris32-10.1.0.3.zip
 
...and don't forget to add ".world" on to the end of your SID. It's very common to have to specify DBNAME.WORLD to connect.
buswash at gmail dot com
02-Feb-2005 09:51
PHP 5.0.3 + Solaris 9 (UltraSPARC) + Apache 2.0.51 + Oracle 10g Instant Client 10.1.0.3

Thanks to Jakob's patch I got this combination working.  Here are some things that helped me:

1. After getting this:
ld: fatal: file /opt/oracle/instantclient/libclntsh.so: wrong ELF class: ELFCLASS64

I realized that PHP is a 32-bit application and that all 3rd-party libraries need to be 32-bit as well.  You need to download the 32-bit version of Instant Client (basic + sdk), even if you are running the 64-bit Solaris OS.

2. My patch command syntax was a little different:
patch -p0 -i php5_ociclient.patch config.m4

Thanks again to Jakob for porting the patch over to PHP 5.

Marc
jakob dot jellbauer at interhyp dot de
19-Jan-2005 03:00
Yes, i`ve made it !
Installing PHP 5.0.3 and the Oracle 10g Instant Client on Linux .

There is no need to have a full Oracle Installation on the Webserver, you only need the client.

http://www.oracle.com/technology/pub/notes/technote_php_instant.html

The patches provided from Oracle are for PHP Versions 4.3.9 or 4.3.10.

Here is the handmade patch for PHP 5.0.3 :

...
patch -u php-5.0.3/ext/oci8/config.m4 php5_ociclient.patch
cd php-5.0.3
rm -rf autom4te.cache config.cache
./buildconf --force
...

Download the Patch here:

 
http://www.pubanz.de/jakob/php5_ociclient.zip

Have fun,

Feel free to ask me if there are any questions
mark at magpies dot net
06-Jan-2005 04:05
Hello once again.
This time I present details on how to get Oracle Instant Client 10g ( 10.1.0.3 ), PHP 5.0.3 and Apache 2.0.52 running together on Linux (I've used fedora core 1 but I can't see why this will not work for any other distro )
*Note* This is not a guide on compiling php and httpd there are plenty of guides around to do that. This just covers compiling and using the oci8 module with php.

1. Set-up and install apache-2.0.52 as per normal

2. Unpack the Oracle 10g Instant Client ( 10.1.0.3 SDK + Basic, I also use the sqlplus pack to test the connection outside of apache / php )
  rpm -ivh oracle-instantclient-basic-10.1.0.3-1.i386.rpm  oracle-instantclient-devel-10.1.0.3-1.i386.rpm  oracle-instantclient-sqlplus-10.1.0.3-1.i386.rpm

3. Set env ORACLE_HOME to the clients path in the current shell your shell command may vary (this is bash )
  export ORACLE_HOME=/usr/lib/oracle/10.1.0.3/client; export LD_LIBRARY_PATH=/usr/lib/oracle/10.1.0.3/client/lib;
(if you want to test if you can now get a connection to oracle using sqlplus see item 10 below.)

4. Unpack php-5.0.3 as per normal add in  --with-oci8  to the configure options. If the ORACLE_HOME is set previously then adding the directory as per "--with-oci8=$ORACLE_HOME" should not be necessary. Do this to be safe though.

5. Run the ./configure program in php source directory. Don't make it just yet though.

6. The compiler needs to find the includes oci.h + others so, from the default client install dirs, I needed to edit the php Makefile after it was configured. Open it up and look for "EXTRA_INCLUDES" and add to end of line
-I/usr/include/oracle/10.1.0.3/client  (thats a capital i ) save the Makefile, then finish off compiling and installing php.  Please note im sure this will be changed in php's configure so it finds these by default in the not too distant future.

7. Create a directory /etc/oracle and place your tnsnames.ora file in there, (VERY IMPORTANT make sure you chmod your tnsnames.ora to ensure that whatever username your httpd server runs under can read the file (1.5 hours of frustration later i figured this out). I just did "chmod 0644 tnsnames.ora" it doesn't matter where you put this as long as you set the env  TNS_ADMIN to it. (IMPORTANT  TNS_ADMIN points to a directory not the actual tnsnames.ora file )

8. My system uses a /etc/init.d/httpd script to start up httpd so in that file I exported the ORACLE_HOME & TNS_ADMIN env vars before the httpd is run, oh you will need to set LD_LIBRARY_PATH as well if you not added the path to ld.so.conf
  export ORACLE_HOME=/usr/lib/oracle/10.1.0.3/client; export TNS_ADMIN=/etc/oracle
 
9. start httpd and bobs your uncle....

10. You can test connection once the instant client rpm's are installed by using  sqlplus.  set  ORACLE_HOME as above,  TNS_ADMIN as above, LD_LIBRARY_PATH as above and if necessary.  Then  sqlplus <username>/<password>@<sid or service_name as per tns_admin file>  use sqlplus here as you would normally

Mark
PS: Thanks Oracle for the SDK,  about time !
Mark at catalyst dot net dot nzed
09-Aug-2004 11:28
ReCompiling PHP4 to have oracle 8 support (oci8) on Debian Linux, using the Oracle 10g client libraries. Log in as root.

PACKAGES REQUIRED:
php4-dev
php4 (source files)
php4 module (might not be required, but it's what i had installed at the time)

OTHER PACKAGE REQUIREMENTS:
Oracle Client Libraries (i used Oracle 10g Server, but you should be able to use, as has been previously said, any set of the oracle client libraries from 8i onwards).
* make sure this is installed before recompiling php4.

ENVIRONMENT REQUIREMENTS:
- export ORACLE_HOME=[where u installed the oracle client]
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
- export LD_PRELOAD=libclntsh.so.10.1 (the version number at the end will correspond to the oracle version you previously installed. in my case, 10g is 10.1).
- vi /etc/ld.so.conf and add $ORACLE_HOME/lib to the list of paths.
then * run ldconfig to reload those changes to the system * (p.s. make sure it's the full path, and not using any environment variables. e.g. /u01/app/oracle/product/10gRDBMS is my ORACLE_HOME).

STEPS:
- cd /usr/src/[PHP4 Version]
in my case, [PHP4 Version] = php4-4.3.8, so path was
/usr/src/php4-4.3.8

- vi debian/rules
these are the default compilation rules for php4. Find section labeled COMMON_CONFIG = [...] and add --with-oci8 (it should be near the top of the file).

- debchange -i (allows you to edit the change log for the versions of php. btw - you should be in the php4 source code directory). give the version id something obviously unique. don't forget to add a comment.

when all is in readyness, then you should be able to go debian/rules binary to build the debian packages required.
the deb packages are built into the /usr/src directory. and depending on the default compilation options u choose, there should be a few. find the deb package that corresponds to the main php4 module (php4_4.3.8-4.mark.1_i386.deb for me), and run dpkg -i [package name] to install it.

- vi /etc/init.d/apache and add exports for $ORACLE_HOME, $LD_PRELOAD and $LD_LIBRARY_PATH

* don't forget to restart apache /etc/init.d/apache to reload the php4 module. *

IF YOU GET... :
if you get an error saying something about apache cannot load libclntsh.so.10.1, file not found, check the environment variables, for both the user, and in /etc/init.d/apache and also check ld.so.conf to make sure the $ORACLE_HOME/lib path is in there, and has been reloaded (with ldconfig).

editing ld.so.conf was the part that finally got it working for me.
as you should be able to tell, the steps are pretty much the same as for all oracle versions 8i onwards, and all linux OS's. but with a few debian specific paths and commands thrown in.
mark at magpies dot net
05-Jul-2004 12:07
For those trying to use the Oracle Instant Client 10g in a win32 environment, heres a nice easy howto. If you fully read the docs properly and understand what your reading you will be able to set it up, but if like me you want a quick easy fix, heres how I did it.

1. Download and install the Oracle Instant Client to where ever (lets say  c:oraclient  )
2. Add your connect info, copy a previously created or provided tnsnames.ora file to the above directory.
3. Change Path in the Environment Variables area to add this directory to the path. ie.  c:oraclient;%SystemRoot%;<and so on>
4. Open regedit and add a Key called ORACLE to HKEY_LOCAL_MACHINESOFTWARE
5. To the ORACLE key add a string value called TNS_ADMIN and assign it the directory above (ie. c:oraclient )  So you end up with KEY_LOCAL_MACHINESOFTWAREORACLETNS_ADMIN = c:oraclient
6. Set php to use Oci8 extension and bobs your uncle
7. Reboot.

Option 7 was required as the oci8 extension or php wouldn't pick up the path change. Also my problem was how to use other programs like sqlplus without creating extra Environment Variables etc the TNS_ADMIN / tnsnames.ora part makes that simpler and allows you to call things the same as you would before.

PS: This should apply to all the Instant Clients. I haven't tried it with any others but 10g though.

Hope this helps.
beckman at purplecow dot com
14-Jun-2004 07:20
For those of you running Oracle on Linux, and running a remote box also on Linux, here's an easy way to get OCI8 working without having to install the whole Oracle DB just to get your client working.

[PS -- For the life of me, installing client libraries for Oracle really shouldn't be this hard, but it really truly is.]

Step 1.  Copy the following directories from your ORACLE_HOME directory where Oracle is installed (the database server) to your remote client server/machine:

     lib, network, ocommon, plsql, rdbms, oracore

   These contain all of the files/folders/libraries you'll need to compile OCI8 into PHP.  I put this in /home/beckman/oracle and set ORACLE_HOME as that dir.

Step 2.  Compile PHP with --with-oci8=/home/beckman/oracle (obviously using your directory, not mine).  Install, (re)start apache.

Step 3. Remove plsql and rdbms directories from ORACLE_HOME on your remote server, leaving you with lib, network, ocommon and oracore.

Step 4. Read:
http://otn.oracle.com/tech/opensource/php/php_troubleshooting_faq.html

NOTE: This will only help you if you (a) have Oracle successfully running on Linux (was RH Enterprise 3 for me) and your client box is running the same OS.  I'm not sure it will work on earlier versions, but it may.  Your results should be posted here methinks!
cyrill@_malevanov_dot_spb_dot_ru
10-May-2004 04:05
Passing CLOB to stored procedure and retrieve CLOB too (function lobinout(a in clob) return clob)

<?
   error_reporting
(1+2+4+8
);
  
$conn = OCILogon('batdtd', 'batdtd', 'batxml'
);
  
  
$lobin = OCINewDescriptor($conn, OCI_D_LOB
);
  
$lobout = OCINewDescriptor($conn, OCI_D_LOB
);
  
  
$stmt = OCIParse($conn, "declare rs clob; begin :rs := lobinout(:par); end;"
);
  
$lob_data = 'abcdefgh'
;
  
   echo
"binding lobin..."
;
  
OCIBindByName($stmt, ':par', $lobin, -1, OCI_B_CLOB
);
  
   echo
"done<br>binding rs..."
;
  
  
OCIBindByName($stmt, ':rs', $lobout, -1, OCI_B_CLOB
);
  
   echo
"done<br>writing temp lob..."
;
            
// here we pass data to func
  
$lobin -> WriteTemporary($lob_data
);
   echo
"done<br>executing..."
;
  
  
OCIExecute($stmt, OCI_DEFAULT
);
            
// here we load data returned from func
  
echo "done<br>rs = ".$lobout->load
();
  
OCICommit($conn
);
  
$lobin -> free
();
  
$lobout -> free
();
  
OCIFreeStatement($stmt
);
  
OCILogoff($conn
);
?>
dadarden_nospamoladude at iti2 dot net
12-Mar-2004 08:27
PHP Oracle -- Compiling Oracle Support into PHP, Apache 2
Apache 2.0.48,  Php 4.3.4,  Red Hat Linux 9.0,  Debian 3.0,  Oracle 9i R2
Dave Darden ? 1/17/04 -- www.dardensystems.com

First install Apache 2 from source.  Instructions are at
http://httpd.apache.org/docs-2.0/install.html. 
I used a --prefix=/usr/local/apache on the install. 

Install Oracle.  There is a very good Oracle install to RedHat 9.0 white paper at
http://www.dizwell.com/ that goes step by step through the problems (Oracle is not supported on RedHat 9.  Oracle only supports installation on paid versions of Red Hat). 

If only an Oracle client is installed on the web server (if the database is on another machine in a multi-tier configuration) then you must install both the client and the Oracle Call Interface (OCI).  I think SQLPlus also needs to be installed.  Oracle Network Utilities and Installation Common Files were also installed.  If you cannot configure/make php because of missing Oracle library errors during configure/make, then investigate whether you have installed enough of the ?client? pieces of Oracle on the web server machine. 

I also included a link from  libclntsh.so.8.0  to  libclntsh.so.9.0  in the $ORACLE_HOME/lib directory.  Some internet posts suggested it to prevent errors in php configure/make.  A later experience moving from RedHat to Debian confirms that it is necessary to avoid a make error on a missing lclntsh file. 

In transferring the client software from a Red Hat 9.0 web server installation to a Debian 3.0 (kernel 2.4.18) web server installation I was able to simply copy over the Oracle /u01 directory tree without rerunning the Oracle client installation.  This must be done before php is configured and compiled on the Debian machine so the oci8 libraries are available.  And of course the tips on libclntsh and environment variables must be observed as well. 

Get the php source.  This php configure line worked for me, creating an Apache 2 module, and keeping mysql and gd support.  Add other options if you need them for a given site.  For some reason, even though gd is included with php now, zlib was needed to successfully configure and make php from source when including gd.  You will need to substitute appropriate directory locations for your install of Apache, zlib, and Oracle.

./configure --with-apxs2=/usr/local/apache/bin/apxs
--with-mysql --with-gd
--with-zlib-dir=/usr/local
--with-config-file-path=/etc
--enable-force-cgi-redirect --disable-cgi
--with-oci8=/u01/app/oracle/9i --enable-sigchild

Use an absolute path on  -?with-oci8=/u01/app/oracle/9i 
(Do not use the $ORACLE_HOME path variable in the configure statement.  For some reason it does not work even when it is set properly.)

Also, set the environment variables in
/usr/local/apache/bin/envvars like so (your env var values should vary):

export ORACLE_SID="lx92"
export ORACLE_HOME="/u01/app/oracle/9i"
export TNS_ADMIN="/u01/app/oracle/9i/network/admin"
export LD_LIBRARY_PATH="/u01/app/oracle/9i/lib"
export TNS_ADMIN="/u01/app/oracle/9i/network/admin/tnsnames.ora"
export TWO_TASK="/u01/app/oracle/9i/network/admin/tnsnames.ora"
export NLS_LANG="English_America.WE8ISO8859P1"
export ORACLE_BASE="/u01/app/oracle"
oddbec_no_more_spam_kthx at online dot no
24-Feb-2004 11:49
I had trouble with norwegian characters using oracle 8.7.1 / php 4something and Apache 2.

The only trouble was that '?' appeared instead of the norwegian characters.

The solution to it all was to add this to the apachectl script:

export NLS_LANG="norwegian_norway.WE8ISO8859P1"
export ORACLE_BASE="/home/oracle"
export ORA_NLS33="/home/oracle/ocommon/nls/admin/data"
export ORACLE_TERM="ansi"
export ORACLE_HOME="/home/oracle"
export LANG="no_NO"

I'm not sure if all of these are necessary, but I took no change, and it works now :)
lomax at arizona edu
25-Jul-2003 07:26
Can't compile php with Oracle 9i and apache on Solaris8?
Sun 280R

Using some of the tips below I had to add this:
(static build)

#!/bin/tcsh
setenv LDFLAGS -L$ORACLE_HOME/lib32

cd php-4.x.x/
./configure --with-oci8=$ORACLE_HOME --with-apache=/path/to/apache_src ..etc
make
make intsall

cd apache_src
(make sure environment variable is still set)
./configure  "--prefix=/usr/apache" "--enable-module=so"
"--activate-module=src/modules/php4/libphp4.a"  ...etc
make
make install

Having the gcc compilier build php against oracle 32 bit libraries was the key, but without setting LDFLAGS the compiler defaults to using the 64-bit oracle libraries which cause the famous
"...wrong ELF class: ELFCLASS64.." on startup.

The only diffenece here was I didn't have to do play musical directories for it to work. The below post was instrumental in helping me to get this fixed. Thanks to "lore_giver at lycos dot co dot uk"
lore_giver at lycos dot co dot uk
20-May-2003 02:42
Running Oracle 9i on a
Solaris 9 (64 bit) platform with a Sun Server E250:
Apache version 1.3.27
PHP version 4.3.1

I was first getting "...wrong ELF class: ELFCLASS64.."
while doing a ./configure with the --with-oci8 and --with-oracle parameters.

After some unsuccessfull searched I renamed the $ORACLE_HOME/lib to $ORACLE_HOME/lib.org and then renamed the
$ORACLE_HOME/lib32 to $ORACLE_HOME/lib

Thereafter it went passed this config, but now failed on
not being able to find a libwtc9.so file which was in the
$ORACLE_HOME/lib directory  (this message was displayed in the debug.log in the php source directory).

After setting the Environment variable:
LD_LIBRARY_PATH=$ORACLE_HOME/lib
I was able to compile without any errors and 'make' and

Press ESC to close