PHP: Oracle 8 f�ggv�nyek - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links 
search for in the  
previousdeaggregateOCIBindByNamenext
Last updated: Fri, 30 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to English | Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Swedish | Turkish

LXX. Oracle 8 f�ggv�nyek

Ezekkel a f�ggv�nyekkel az Oracle8 �s Oracle7 adatb�zisokat �rheted el, az Oracle8 Call-Interface (OCI8) haszn�lat�val. Az Oracle8 kliens k�nyvt�rakra sz�ks�ged lesz, ha szeretn�d ezt a kiterjeszt�st haszn�lni.

Ez a kiterjeszt�s rugalmasabb, mint a hagyom�nyos Oracle kiterjeszt�s. Lehet�v� teszi glob�lis �s lok�lis PHP v�ltoz�k k�t�s�t Oracle �rt�kekhez, teljes LOB, FILE �s ROWID t�mogat�ssal rendelkezik, �s lehet�v� teszi a felhaszn�l� �ltal megadott v�ltoz�k haszn�lat�t.

Miel�tt elkezden�d haszn�lni ezt a kiterjeszt�st, gy�z�dj meg r�la, hogy az Oracle k�rnyezeti v�ltoz�k helyesen be vannak �ll�tva az Oracle �s a webszerver felhaszn�l� sz�m�ra. Az �rt�kek, amiket esetleg be kell �ll�tanod a k�vezkez�k:

  • ORACLE_HOME

  • ORACLE_SID

  • LD_PRELOAD

  • LD_LIBRARY_PATH

  • NLS_LANG

  • ORA_NLS33

Miut�n be�ll�tottad a k�nyezeti v�ltoz�kat a webszerver felhaszn�l� sz�m�ra, add hozz� a webszerver felhaszn�l�t (nobody, www) az oracle csoporthoz.

Ha a webszerver nem indul el, vagy lefagy indul�skor: Ellen�rizd, hogy az Apache szervert a pthread k�nyvt�rral ford�tottad-e:

# 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)

Ha a libpthread nincs bent a list�ban, �jra kell telep�tened az Apache szervert:

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

P�lda 1. OCI tippek

<?php
// A tippeket [email protected] k�ldte be

// Haszn�ld az OCI_DEFAULT opci�t a v�grehajt�sn�l,
// ha k�sleltetni szetern�d a v�grehjt�st
OCIExecute($stmt, OCI_DEFAULT);

// Lek�rdezett adatok haszn�lat�hoz (fetch ut�n):

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

// INSERT vagy UPDATE parancsokhoz:

$sql = "insert into table (mezo1, mezo2) values (mezo1 = '�rt�k',
 mezo2 = empty_clob()) returning mezo2 into :mezo2";
OCIParse($conn, $sql);
$clob = OCINewDescriptor($conn, OCI_D_LOB);
OCIBindByName($stmt, ":mezo2", &$clob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
$clob->save("valami sz�veg");
OCICommit($conn);

?>

K�nnyen el�rheted a t�rolt elj�r�sokat, �ppen �gy, mint parancssorb�l.

P�lda 2. T�rolt elj�r�sok haszn�lata

<?php
// [email protected] k�ldte be a k�vetkez� k�dot:

$sth = OCIParse ( $dbh, "begin sp_newaddress( :cimid, '$keresztnev',
 '$csaladinev', '$ceg', '$cim1', '$cim2', '$varos', '$megye',
 '$irszam', '$orszag', :hibakod );end;" );

// Ez a parancs megh�vja az sp_newaddress nev� t�rolt elj�r�st,
// a :cimid ki �s bemeneti v�ltoz�val �s a :hibakod kimeneti
// v�ltoz�val. Ezut�n a v�ltoz� k�t�seket kell elv�gezni:

   OCIBindByName ( $sth, ":cimid", $cimid, 10 );
   OCIBindByName ( $sth, ":hibakod", $hibakod, 10 );
   OCIExecute ( $sth );

?>

Tartalom
OCIBindByName --  PHP v�ltoz� k�t�se egy Oracle �rt�khez
OCICancel -- Kurzorral olvas�s befejez�se
OCICollAppend -- [Eddig] nem dokument�lt
OCICollAssign -- [Eddig] nem dokument�lt
OCICollAssignElem -- [Eddig] nem dokument�lt
OCICollGetElem -- [Eddig] nem dokument�lt
OCICollMax -- [Eddig] nem dokument�lt
OCICollSize -- [Eddig] nem dokument�lt
OCICollTrim -- [Eddig] nem dokument�lt
OCIColumnIsNULL -- NULL �rt�k� mez� azonos�t�sa
OCIColumnName -- Oszlop neve egy eredm�nyt�bl�ban
OCIColumnPrecision -- [Eddig] nem dokument�lt
OCIColumnScale -- [Eddig] nem dokument�lt
OCIColumnSize -- Oszlop m�rete egy eredm�nyt�bl�ban
OCIColumnType -- Oszlop adatt�pusa egy eredm�nyt�bl�ban
OCIColumnTypeRaw -- [Eddig] nem dokument�lt
OCICommit -- F�gg�ben l�v� tranzakci�k v�grehajt�sa
OCIDefineByName --  PHP v�ltoz� haszn�lata a defini�l�si l�p�sben egy SELECT sz�m�ra
OCIError -- A legut�bbi parancs / kapcsolat / �ltal�nos hiba visszaad�sa
OCIExecute -- Parancs futtat�sa
OCIFetch -- A k�vetkez� eredm�ny sor lek�rdez�se
OCIFetchInto -- A k�vetkez� sor lek�rdez�se t�mbbe
OCIFetchStatement -- Miden eredm�nysor lek�rdez�se egy t�mbbe
OCIFreeCollection -- [Eddig] nem dokument�lt
OCIFreeCursor --  Kurzorhoz rendelt er�forr�sok felszabad�t�sa
OCIFreeDesc -- Felszabad�t egy LOB le�r�t
OCIFreeStatement --  Parancshoz rendelt er�forr�sok felszabad�t�sa
OCIInternalDebug --  A bels� debug kimenet enged�lyez�se / letilt�sa
OCILoadLob -- [Eddig] nem dokument�lt
OCILogOff -- Oracle kapcsolat bont�sa
OCILogon -- Oracle adatb�zis kapcsolat l�tes�t�se
OCINewCollection -- [Eddig] nem dokument�lt
OCINewCursor --  �j kurzor (parancs eredm�ny kezel�) megnyit�sa
OCINewDescriptor --  Egy �j �res LOB vagy FILE le�r�t hoz l�tre
OCINLogon -- �j Oracle adatb�zis kapcsolat l�trehoz�sa
OCINumCols --  Az eredm�nyoszlopok sz�ma egy eredm�nyt�bl�ban
OCIParse -- SQL lek�rdez�s feldolgoz�sa, parancs visszaad�sa
OCIPLogon -- Oracle adatb�ziscsatlakoz�s �lland� kapcsolattal
OCIResult -- Mez� �rt�k�nek visszaad�sa lek�rdezett sorb�l
OCIRollback -- F�gg�ben l�v� tranzakci�k visszavon�sa
OCIRowCount -- Az �rintett sorok sz�ma
OCISaveLob -- [Eddig] nem dokument�lt
OCISaveLobFile -- [Eddig] nem dokument�lt
OCIServerVersion -- Szerver verzi� inform�ci� visszaad�sa
OCISetPrefetch -- Az el�zetesen leh�vott sorok sz�m�nak be�ll�t�sa
OCIStatementType -- OCI parancs t�pus�t adja vissza
OCIWriteLobToFile -- [Eddig] nem dokument�lt
User Contributed Notes
Oracle 8 f�ggv�nyek
add a note about notes
[email protected]
19-May-2000 02:14

If you're using OCI calls from apache/mod_php, and getting ORA-12514 errors, it's important to make sure your ORACLE_HOME environment variable is defined when you start apache. If you use /etc/rc.d/init.d/httpd to start apache, simply put the environment variable definition in there.

This ORA-12514 error is baffling, because there isn't any such error code. It actually should be ORA-12154 (but there's an error-code transposition somewhere in Oracle 8.1.5.0.2, on Linux).

[email protected]
19-May-2000 02:19

To suppress the verbose Oracle error messages, put an @ sign before the PHP function call. For a practical example:

if (@OCIFetch($stmt)) {
/* found a row, do something */
} else {
/* found no row, handle it */
}

[email protected]
03-Aug-2000 10:47

I also posted the following note to the Unix installation page, but I thought I should add it here as well since it only happened once I included OCI8 into the build.


-------------------------------------
When compiling and installing on Solaris, you might encounter a but that occurs only when you try and start apache - in otherwords, the module compiles fine but it won't run!

The specific error is that it can't find a symbol called "__muldi3". From what I can tell, this is an internal symbol created by gcc and the problem happens when you compile the code with gcc and then use a different linker.

To fix the problem, make sure that there is only one 'ld' program in your $PATH and that you also specify '--with-gnu-ld' in your configuration.

[email protected]
04-Aug-2000 12:14

If you would like to make oracle8 sql calls simple for your developers...erm...or for yourself...
Check out:
dbconn.php class object
Oracle8 made easy.

[email protected]
03-Oct-2000 10:43

couple of notes about startup/shutdown on linux: (redhat, maybe others)

export LD_PRELOAD=/usr/lib/libpthread.so

Caused the start/stop script to fail to stop the httpd process.
The LD_PRELOAD environment var caused the 'ps' command to core dump. I went bald figuring that out.

Easiest fix I could think of was to move all the oracle/php varialble exports so they are only set in the start section of the httpd script.

Never thought setting those vars globally in the script would cause problems. That's what I get for thinking...

One other note: Make sure the httpd process is shutdown before Oracle.

eg:
/etc/rc.d/rc0.d/K15httpd
/etc/rc.d/rc0.d/K25Oracle

Lingering connections to oracle may cause shutdown to take forever.

gl & hf

-Joe

[email protected]
06-Oct-2000 10:19

*cough* Deleted this note that could actaully be useful..

[email protected] writes
=======================
<i>Call me dumb, but I can't get OCI8 working with PHP4rc2 and Apache 1.3.9. I configured PHP --with-oracle</i>

I had a similar problem

Try --with-oci8 instead

I should likely wait until I have it the whole thing working before posting, but I think I am at least accessing the functions now because they are returning ORA errors.

My phpinfo() page appears to be right. It gives me information on oci8.

[email protected]
17-Oct-2000 01:12

In order to get the OCI8 support to work in Apache1.3.12/PHP 4.0.3pl1 on Redhat 6.2, I needed to set the environment variable "LD_PRELOAD=libclntsh.so.8.0" in Apache's startup file. Without it the httpd daemon would not start. Setting the normal Oracle enivironment (including LD_LIBRARY_PATH) was not enough.
[email protected]
19-Oct-2000 09:39

Here's a clue about rowid.

Don't forget about the oracle functions:

"rowidtochar" and "chartorowid"

"select rowidtochar(rowid) as FOO from table ...."

When you want to pass the rowid in a form or link, that's
the only way to go.

[email protected]
28-Nov-2000 11:22

After I finally managed to compile PHP 4.0.3pl1 (./configure --with-mysql --with-oci8 -with-apxs=/usr/local/apache/bin/apxs --enable-trans-sid) for accessing Oracle on another machine (I first had to install the Oracle client on the webserver and copy some files (that PHP was missing during make) from the Oracle Server to $ORACLE_HOME/rdbms/demo on the webserver) I got the very annoying message: "Warning: _oci_open_server: Error while trying to retrieve text for error ORA-12154".
I was looking here and on the web and finally found the problem: when I installed the Oracle Client it didn't allow me to install it as root, so I installed it with my user and everything went into my homedirectory (:-|). On the other hand apache is running with user and group nobody (httpd.conf). Since I replaced user and group in httpd.conf with the user and group with which I installed the oracle client everthing works smooth. Hope this helps to prevent some headache.

[email protected]
04-Dec-2000 03:06

In my case, using OCI8 under Unix (Solaris2.7), the global variable TNS_ADMIN must be set to the directory containing 'tnsnames.ora' prior to connecting to the base:
putenv('ORACLE_HOME=/.../oracle');
putenv('TNS_ADMIN=/.../oracle/network/admin');
$idDB = OCILogon( $User,$Psw,$SIDalias );

Otherwise, an error ORA-12154 is generated.

[email protected]
06-Dec-2000 05:38

If you are using several selects and updates, ignore_user_abort, is essential for preventing partially completed records and bad data.

Took me a while to find this function.

[email protected]
16-Jan-2001 03:28

When trying to compile PHP 4 with Oracle 8.1.6 support on a SuSE 7.0 system, make sure that you have added the following line to your /sbin/init.d/apache Skript, or you will get many many segmentation faults:
LD_PRELOAD=libclntsh.so.8.0
EXPORT LD_PRELOAD

Someone posted here a note that this is also required for RedHat 6.2. I can confirm this, both for RedHat and Suse (7.0).

[email protected]
23-Apr-2001 12:04

Add a link to "
[email protected]
22-May-2001 02:14

When using PHP4 in CGI-mode with Windows NT or Windows 2000 with IIS or Apache, make sure that the TNSNAMES.ORA and the SQLNET.ORA do not contain DOS/Windows CR/LF line endings.
Instead, they must have UNIX (only LF) endings. Otherwise, you will get an ORA-12154 error (TNS cannot resolve service name) when connecting to a remote database.

This all does not matter if you use the ISAPI mode.

Frank

[email protected]
23-May-2001 10:48

VERY IMPORTANT! OCIPLogon only keeps a persistent connection if you are running PHP as a module. This is particularly important to Windows users who are used to running PHP as a CGI.
[email protected]
29-May-2001 03:59

<?PHP
// In diesem Beispiel wird beschrieben wie man eine StoredProcedure aufruft,
// einen Integer �bergibt und diesen wieder ausgibt.

// Oracle Client mu� installiert sein und die extension php_oci8 mu� installiert sein!
// Bei dem Beispiel: ps
// Host-Name: rechner
// Port-Nummer: 1521

// Variablen
$usr = "Dein User";
$pwd = "Dein Passwort";
$sid = "Dienstname";

// Verbindung zum Oracle-Server herstellen
$conn = OCILogon ($usr, $pwd, $sid);

// SoredProcedure t_phpsaveproc(integer) aufrufen
$stmt = OCIParse($conn, "begin :result := t_phpsaveproc(1); end;");

// OCIBindByName bindet die Variable result an den Platzhalter $result
OCIBindByName($stmt, "result", &$result);

// Commit, hier werden die "Jobs" ausgef�hrt.
OCIExecute($stmt);

// Mit OCIResult wird der R�ckgabewert der StoredProcedure aus der Menge in die PHP-Variable $result geschrieben
OCIResult($stmt,$result);

// Ausgabe des R�ckgabewertes
echo $result;

// Verbindung zum Oracle-Server schlie�en
ocilogoff($conn);
?>

31-May-2001 07:25
At last I successfully compile the php 4.0.3pl1 --with-oci8 support. This is my configuration

Platform - Redhat 7.0
Webserver - Apache 1.3.14
Remote Oracle ver - 8.1.6 (Redhat 7.0 platform)


The steps

i. Copy these directory from oracle server to my own server (opt/oci8)
- ../rdbms/demo
- ../lib
- ../network/public
- ../plsql/public

ii. Add this to /etc/profile file
ORACLE_HOME=/opt/oci8
LD_LIBRARY_PATH=/opt/oci8/lib

export ORACLE_HOME LD_LIBRARY_PATH

iii. relogin

iv. Compile the php with
./configure --with-mysql --with-oci8
--with-apxs=/usr/local/apachedev/bin/apxs --enable-trans-sid --enable-sigchild

make
make install

v. When I run apachectl start, I got this error
syntax error on line 207 of /usr/local/apache/conf/httpd.conf
cannot load /usr/local/apache/libexec/libphp4.so into server:
libclntsh.so.8.0:
cannot open object file: No Such file or directory.

then I did this;

vi /etc/ld.so.conf and add this path
/opt/oci8/lib

then I run /sbin/ldconfig

vi. run apachectl start

YES, ... its running very well.

vii. Then I try this oracle.php code test (Please change the parameter according to yours)

<?php

$db = " (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.12.1)(PORT = 1521))
(CONNECT_DATA = (SID = ORCL))
)";

$c1 = ocilogon("test","test",$db);

if ($c1 == false){
echo OCIError($connection)."";
exit;
}
else
{
echo "success";
}

?>

YES, no error but success.

Good luck to you all.


Tips: If your webserver is on redhat linux, get the redhat linux oracle server library. Same apply to, solaris and so on.



*My mistake (1 whole day) - trying to compile php using solaris oracle server library and got nothing but errors.


[email protected]
20-Jun-2001 06:25

Oracle 8 and iPlanet Webserver with CGI version of PHP on solaris 2.6/8

you have to set the environnements variable for oracle in the obj.conf, setting then inside the php code do not works for NLS_LANG (may be some others)

like:
Init fn="init-cgi" LateInit="yes" ORACLE_HOME="/usr2/oracle8" NLS_LANG="AMERICAN_AMERICA.WE8ISO8859P1"

see netscape info:

[email protected]
11-Jul-2001 08:15

If you are getting the nasty ORA-12154 errors, try adding your http daemon user (listed in you httpd.conf file as "User" & "Group") to the same group as the Oracle Owner user, then be sure that the ORACLE_HOME environment variable is set to the Oracle Home Path, when you start apache.
[email protected]
19-Jul-2001 09:38

if you feel like you have too many oracle statements clouding up your php, i came up with a function to open a connection (if necessary), parse your sql statement, and return the executed query. after you call the function, you can do whatever needs to be done. makes like so much simpler: (do whatever you want with the errors)

function execute_query($query, &$connected) {
global $ORACLE_USER, $ORACLE_PASS, $ORACLE_SID;

if(!$connected) {
$connected = @OCIPLogon($ORACLE_USER, $ORACLE_PASS, $ORACLE_SID);

if($error = OCIError()) {
die("<font color=red>ERROR!! Couldn't connect to server!</font>");
}
}

$stmt = @OCIParse($connected, $query);
if($error = OCIError($cn)) {
die("<font color=red>ERROR!! Statement syntax error!</font>");
}

@OCIExecute($stmt);
if($error = OCIError($stmt)) {
die("<font color=red>ERROR!! Could not execute statement!</font>");
}

return $stmt;
}

[email protected]
23-Aug-2001 09:15

Tom Tsongas has a hint on compiling oci8 with Oracle 9i.
--------------------------------

I built PHP with oracle and oci8 extensions.
I built it as a static module for Apache 1.3.20.
If you are getting errors from running 'configure' (something like it can't
locate the Oracle libraries) its because the Oracle 8 library searched for is
hard coded as libclntsh.so.8.0 corresponding to the older oracle library.
If you create a symbolic link to the oracle 9 library as follows:

ln libclntsh.so.9.0 libclntsh.so.8.0

it will compile and build.

Tom

[email protected]
07-Sep-2001 07:48

Using OCI8 it seems putenv() doesn't seem to work for oracle environment (at least with Linux/Apache) variables, but once you get connected try issuing the sql stament:
ALTER SESSION SET NLS_whatever = value;
Seems to overide any default NLS parameters.

[email protected]
26-Oct-2001 11:28

I had big problems to get an Oracle 7 server working with the OCI8 client and PHP under Linux, while connection to an Oracle 8 server worked great (In fact I got an ORA-01005 when connecting to Oracle 7). I see that more people have this problem, so here is the solution:

1. Make sure the NLS files are in your ORACLE_HOME subtree under $ORACLE_HOME/ocommon/nls/admin/data.

2. Make sure the ORA_NLS33 parameter is unset or alternatively pointing to the above directory ($ORACLE_HOME/ocommon/nls/admin/data).

3. Add "export ORACLE_HOME=/usr/local/oracle" (for example) to your apache startup script. This is important!! Adding this variabele in the httpd.conf OR in your PHP script will _NOT_ solve the problem: the directory has to be known before the Oracle library is loaded.

Thanks to Ron Reidy for helping to tackle this problem.

[email protected]
08-Nov-2001 06:16

<?
// offset and limit feature for oracle 8 database selects

$conn = OCILogon("user","pw","server.world");

$sql="
declare
type c_type is ref cursor;
c_data c_type;
c_null tab.row_id%type;
begin
open :c_data for
select row_id from tab order by row_id;
while :c_data%rowcount < :c_init loop
fetch :c_data into c_null;
end loop;
end;
";

$stmt=OCIParse($conn, $sql);
$curs=OCINewCursor($conn);

$offset=100; // dont fetch the first 100 rows
$limit=10; // we want exactly 10 rows

OCIBindByName($stmt,":c_init",$offset,32);
OCIBindByName($stmt,":c_data",$curs,-1,OCI_B_CURSOR);

OCIExecute($stmt);
OCIExecute($curs);

for ($i=0;$i<$limit&&OCIFetchinto($curs,$cols,OCI_ASSOC);$i++)
print $cols[ROW_ID]."\n";

OCIFreeStatement($stmt);
OCIFreeCursor($curs);
OCILogoff($conn);

?>

[email protected]
08-Jan-2002 07:01

Here's a little snipet that shows how to insert multiple clob fields. Worked for me.

$dbh = OCILogon($dst_user_name, $dst_password, $dst_db_name);

for($i = 0; $i < $src_rec_cnt; $i++) {
$query = "insert into bid (id,time,resume,experience,comments) values ('$id[$i]','$time[$i]',empty_clob(),empty_clob(),empty_clob()) returning resume,experience,comments into :resume,:experience,:comments";

$stmt = OCIParse($dbh, $query);

$clob1 = OCINewDescriptor($dbh, OCI_D_LOB);
$clob2 = OCINewDescriptor($dbh, OCI_D_LOB);
$clob3 = OCINewDescriptor($dbh, OCI_D_LOB);

OCIBindByName ($stmt, ":resume", &$clob1, -1, OCI_B_CLOB);
OCIBindByName ($stmt, ":experience", &$clob2, -1, OCI_B_CLOB);
OCIBindByName ($stmt, ":comments", &$clob3, -1, OCI_B_CLOB);

OCIExecute($stmt, OCI_DEFAULT);

@$clob1->save ($resume[$i]);
@$clob2->save ($experience[$i]);
@$clob3->save ($comments[$i]);

OCICommit($dbh);

[email protected]
04-Mar-2002 10:12

It seems as though the Oracle functions in PHP use the Oracle8 contraints on datatypes, not Oracle8i or higher. For example, the VARCHAR2 datatype in Oracle8i can have a size up to 4000 bytes. When you return the results from A field using this type that has more than 2000 bytes using the OCI functions in PHP it only returns 2000 bytes of the field. Additionally, when you try to do an insert or update to the field with more than 2000 bytes an error (Warning: OCIParse: ORA-01756: quoted string not properly terminated ). In Oracle8 the constraint on size for the VARCHAR2 datatype was 2000 bytes. This is how I arrived at my conclusion. Additionally, the documentation only mentions Oracle* and not Oracle8i. Hopefully this will be corrected in a future version.
[email protected]
26-Mar-2002 12:53

A little help on recompiling apache debianpackage (potato) with pthreads.
1. Get the apache-source: apt-get source apache.
2. Edit debian/rules, add export LDFLAGS=-lpthread.
3. Run "debian/rules binary" to compile new packages with pthreads.

[email protected]
31-Mar-2002 07:19

>When you return the results
> from A field using this type that has
> more than 2000 bytes using the OCI
>functions in PHP it only returns 2000
>bytes of the field.

This remark is wrong. On php 4.1.2 i have no problems inserting/selecting varchar2(4000) fields.

John Lim

[email protected]
25-Apr-2002 12:33

Debian / Apache / PHP oci8 / Oracle

I just wanna tell my experience compiling the oci8 support from php debian sources. It gave me a lot of headache and I think it might be useful for others who use debian.

This is for debian woody (3.0), php 4.1.2, apache 1.3.24, oracle 8.1.7
(of course, it might be useful for other versions)

The Debian packages have not oci8 compiled in, so you must get the sources. Then I edited the debian/rules file and added the following:

on top:

ORACLE_HOME=my_ora_home_here
export ORACLE_HOME
LD_LIBRARY_PATH=/lib:/usr/lib:/$ORACLE_HOME/lib
export LD_LIBRARY_PATH

to the COMMON_CONFIG variable:
--with-oci8=shared,${ORACLE_HOME}

to the modules variable, just bellow the above:
oci8
(like ... mhash, mysql, oci8, odbc ...)

The "shared" keyword was the key for me. Before using it I was getting "ld: cannot find -lclntsh" on the compile time.

This way the compiling with dpkg-buildpackage went fine. If oci8.so does not show up in the modules directory after install, look php-source-path/apache-build/ext/oci8/.libs - it's there.

If this still fails, look also to the oracle-stubs problem. Oracle is compiled against glibc 2.1 and woody comes with 2.2. But oracle gives some stubs libs for work-around the problem. I don't know if this is necessary for the client libs, but I suggest trying. Look at Oracle docs.

Now things goes terribly fine here.
[]'s

Diego Morales,
Porto Alegre - Brazil.

ddc at portalframework.com
14-May-2002 06:30

Sometimes Oracle doesn't cleanup shadow processes when accessed from PHP. To avoid that, check your
$ORACLE_HOME/network/admin/tnsnames.ora file in your Oracle Client directory and remove the (SERVER=DEDICATED) token if is set.

To let Oracle delete shadow process on timeouts, add the following line in your $ORACLE_HOME/network/admin/sqlnet.ora
found in your ORACLE Server directory:

SQLNET.EXPIRE_TIME=n

Where 'n' is the number of minutes to let connection idle befor shutting them out.

[email protected]
30-May-2002 11:32

I spent several hours tracking down error ORA 24374, which would result from only *SOME* of my select statements. This error would be caused if I made a query that would return any non-numerical value. I am running an Apache 1.3.x webserver and PHP 4.2.1.

The fix is to add entries in your httpd.conf file that would export your environment settings. I added these three lines and everything worked like a charm!
SetEnv ORACLE_HOME /path/to/oracle/home
SetEnv ORA_NLS33 /path/to/oracle/home/ocommon/nls/admin/data
SetEnv NLS_LANG AMERICAN

Obviously, if your NLS_LANG is different, you should set it to whatever your NLS_LANG actually is. Ask your friendly DB admin for this information.

Hope this helps someone who treads down the path that I just followed!

Trent

[email protected]
19-Jun-2002 12:42

When using Oracle on Windows, be sure not to activate both the oci8 und the oracle dll in php.ini. If you do that, you'll get strange error messages like "unable to find dll" every time you call a php page.

In this case, use only one extension (in php.ini) and reboot the computer.
It might not work until you rebooted.

[email protected]
05-Jul-2002 04:12

Can php4 support with iPlanet Webserver 6 and Windows 2000 Server and OCI with ORACLE Client 8.05 to connect ORACLE server 8.15
[email protected]
08-Jul-2002 12:19

I had a problem installing PHP with OCI and Orcale support.
The webserver: RedHat 7, Apache, PHP 4.2.1
The dbserver: Solaris 9, Oracle9i
First I had to install the Oracle Client on the webserver, then copy the example src (dbserver:"opt/Oracle9i/app/oracle/product/9.0.1/rdbms" to webserver "ORACLE_HOME/rdbms")
Then compile the PHP src, it will generate a lot of errors. If your errors involve faults in the header files (.h) (oci.h, and more) try to replace the relative path with the absolute path to the requested headerfile.
(you will probably get more errors then when you started, esp with the oci.h file) after you have suceeded take a look at tnsnames.ora (needed for taking contact with the dbserver)

jirnbergATfh-sbgDOTacDOTat
06-Aug-2002 05:52

I installed Oracle 8.1.7 client, mod_php (4.2.2, as DSO) on a RedHat 7.1 (Seawolf) and among others encountered the "cannot find -lclntsh" problem during making. But the already suggested "shared,{$ORACLE_HOME}" solution didnt work for me.
I finally found a solution:

Usually, the linker (ld) complains, that it can't find the clntsh .so / .a files, but they were present (check in the lib dir of $ORACLE_HOME if present, if not execute ../bin/relink as user Oracle and check what the error message says).

As I backtraced the incident, I found in the configure.log file the following lines:

configure: 2842 gcc -o conftest -g -O2 conftest.c -R /usr/lib 1>&5
gcc: unrecognized option '-R'
/usr/lib: file not recognized: Is a directory
collect2: ld returned 1 exit status

It turned out, that in the ./configure script it is checked, wether the compiler supports the -R option.
However, after I commented the lines responsible for this check and told the script, that my compiler wont support "-R" and as well doesnt need to check, after a make clean and ./configure it actually could be compiled.

You can find the lines I commented by searching for the regexp check.*-R. Comment from there till the next "else" and a "fi" a few lines below. Good Luck!

Josef Irnberger

[email protected]
21-Aug-2002 11:20

After days of head banging, here is the correct way to install php as an apache module with oracle support:

1) su - oracle_user
su root

//This way you assure that php will find oracle libs

2) On Apache's source directory:

./configure --prefix=/usr/local/apache

3) On PHP's source directory:

./configure --with-oci8 --with-oracle --with-apache=../apache_src_dir --enable-track-vars --enable-sigchild

make
make install

cp libs/libphp4.a ../apache_src_dir/src/modules/php4

4) On Apache's src dir:

./configure --prefix=/usr/local/apache --activate-module=src/modules/php4/libphp4.a

LIBS=-lpthread ./config.status

make
make install

5) On PHP's src dir:

cp php.ini-dist /usr/local/lib/php.ini

6) Edit httpd.conf on /usr/local/apache/conf and add the following line (if doesn't exists):

AddType application/x-httpd-php .php

This will make everything works, without two-task errors and stuff.

Regards.

[email protected]
23-Aug-2002 04:46

About PHP with win2000 and Oracle 8.

If you try to include oci8 extension and php hangs at that (without error messages), check your Oracle client version.

I had client for 8.0.5 but server was 8.1.7. This worked well with other apps but not with php4.2.2. Updating oracle client to 8.1.7 cured the problem.

Maybe oci8 extension doesn't work with oracle 8.0.5 libs at all?

add a note about notes
previousdeaggregateOCIBindByNamenext
Last updated: Fri, 30 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Wed Sep 4 00:18:56 2002 CEST