PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<deaggregateoci_bind_by_name>
view the version of this page
Last updated: Sun, 02 May 2004

LXXIV. Funzioni Oracle 8

Introduzione

Queste funzioni permettono di accedere ai database Oracle9, Oracle8 e Oracle7. Usano la Oracle Call Interface (OCI).

Questa estensione è più flessibile della estensione precedente di Oracle. Supporta il binding di variabili PHP locali e globali ai segnaposto Oracle, ha pieno supporto di LOB, FILE e ROWID e permette di utilizzare variabili di definizione personalizzabili. Si raccomanda di utilizzare questa estensione al posto della vecchia estensione quando possibile;

Requisiti

Occorre avere installate le librerie client di Oracle per utilizzare questa estensione. Gli utenti Windows necessitano almeno della versione 8.1 di Oracle per utilizzare la dll php_oci8.dll.

Prima di usare questa estensione, occorre sincerarsi di aver impostato le variabili d'ambiente per l'utente Oracle, come pure per l'utente del server web. Le variabili che potrebbero necessitare l'impostazione sono le seguenti:

  • ORACLE_HOME

  • ORACLE_SID

  • LD_PRELOAD

  • LD_LIBRARY_PATH

  • NLS_LANG

  • ORA_NLS33

Dopo aver impostato le variabili d'ambiente per l'utente del server web, occorre sicerarsi di aver aggiunto anche l'utente stesso (nobody, www) al gruppo oracle.

Se il server web non parte o va in blocco: Controllare che apache sia linkato con la libreria 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)

Se la libpthread non compare nell'elenco, occorre reinstallare Apache:

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

Si noti che su alcuni sistemi, come ad esempio UnixWare, la libreria si chiama libthread invece di libpthread. PHP e Apache devono essere configurati con EXTRA_LIBS=-lthread.

Installazione

Si deve compilare PHP con l'opzione --with-oci8[=DIR], dove DIR è di default il contenuto della variabile di ambiente ORACLE_HOME.

Configurazione di Runtime

Questa estensione non definisce alcuna direttiva di configurazione in php.ini

Tipi di risorse

Costanti predefinite

Queste costanti sono definite da questa estensione e sono disponibili solo se l'estensione è stata compilata nel PHP o se è stata caricata dinamicamente a runtime.

OCI_DEFAULT (integer)

Modalità di esecuzione dello statement. Non viene eseguito il commit automatico utilizzando questa modalità.

OCI_DESCRIBE_ONLY (integer)

Modalità di esecuzione dello statement. Utilizzare questa modalità se non si vuole eseguire la query, ma solamente ricevere la descrizione della select list.

OCI_COMMIT_ON_SUCCESS (integer)

Modalità di esecuzione dello statement. Vene eseguito automaticamente il commit dello statement dopo la chiamata della oci_execute().

OCI_EXACT_FETCH (integer)

Modalità di recupero dati dello statement. Utilizzato quando l'applicazione conosce in anticipo quante righe verranno recuperate. Questa modalità disattiva il prefetching negli Oracle release 8 o successivi. Il cursore viene eliminato dopo che le sono state caricate e ciò può determinare un utilizzo ridotto delle risorse del server.

OCI_SYSDATE (integer)

OCI_B_BFILE (integer)

Utilizzato con oci_bind_by_name() quando si collegano i BFILE.

OCI_B_CFILEE (integer)

Utilizzato con oci_bind_by_name() quando si collegano i CFILE.

OCI_B_CLOB (integer)

Utilizzato con oci_bind_by_name() quando si collegano i CLOB.

OCI_B_BLOB (integer)

Utilizzato con oci_bind_by_name() quando si collegano i BLOB.

OCI_B_ROWID (integer)

Utilizzato con oci_bind_by_name() quando si collegano i ROWID.

OCI_B_CURSOR (integer)

Utilizzato con oci_bind_by_name() quando si collegano i cursori, precedentemente allocati con oci_new_descriptor().

OCI_B_NTY (integer)

Utilizzato con oci_bind_by_name() quando si collegano i named data type.

OCI_B_BIN (integer)

SQLT_BFILEE (integer)

Alias di OCI_B_BFILE.

SQLT_CFILEE (integer)

Alias di OCI_B_CFILEE.

SQLT_CLOB (integer)

Alias di OCI_B_CLOB.

SQLT_BLOB (integer)

Alias di OCI_B_BLOB.

SQLT_RDD (integer)

Alias di OCI_B_ROWID.

SQLT_NTY (integer)

Alias di OCI_B_NTY.

OCI_FETCHSTATEMENT_BY_COLUMN (integer)

Modalità di default di oci_fetch_all().

OCI_FETCHSTATEMENT_BY_ROW (integer)

Modalità alternativa di oci_fetch_all().

OCI_ASSOC (integer)

Utilizzato con oci_fetch_all() e oci_fetch_array() per ottenere un array associative come risultato.

OCI_NUM (integer)

Utilizzato con oci_fetch_all() e oci_fetch_array() per ottenere un array enumerativo come risultato.

OCI_BOTH (integer)

Utilizzato con oci_fetch_all() e oci_fetch_array() per ottenere un array con indici sia associativi che numerici.

OCI_RETURN_NULLS (integer)

Utilizzato con oci_fetch_array() per ottenere elementi dell'array vuoti se il valore del campo è NULL.

OCI_RETURN_LOBS (integer)

Utilizzato con oci_fetch_array() per ottenere il valore del LOB invece del suo descrittore.

OCI_DTYPE_FILE (integer)

Questo flag ordina a oci_new_descriptor() di inizializzare un nuovo descrittore di FILE.

OCI_DTYPE_LOB (integer)

Questo flag ordina a oci_new_descriptor() di inizializzare un nuovo descrittore di LOB.

OCI_DTYPE_ROWID (integer)

Questo flag ordina a oci_new_descriptor() di inizializzare un nuovo descrittore di ROWID.

OCI_D_FILE (integer)

Alias di OCI_DTYPE_FILE.

OCI_D_LOB (integer)

Alias di OCI_DTYPE_LOB.

OCI_D_ROWID (integer)

Alias di OCI_DTYPE_ROWID.

Esempi

Esempio 1. Trucchi OCI

<?php
// by sergo at bacup dot ru

// Usare l'opzione OCI_DEFAULT nel comando execute per ritardare l'esicuzione
OCIExecute($stmt, OCI_DEFAULT);

// per ricevere i dati utilizzare (dopo il fetch):

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

// come comandi INSERT o UPDATE usare:

$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", &$clob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
$clob->save("some text");
OCICommit($conn);

?>

You can easily access stored procedures in the same way as you would from the commands line.

Esempio 2. Using Stored Procedures

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

// Questo codice richiama la stored procedure sp_newaddress, dove :address_id è
// una variabile in/out e :error_code è una variabile out.
// Quindi si effettua il binding:

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

?>

Sommario
oci_bind_by_name --  Lega una variabile PHP ad un segnaposto Oracle
oci_cancel -- Interrompe la lettura del cursore
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 --  Bind a PHP variable to an Oracle Placeholder
ocicancel -- Interrompe la lettura del cursore
ocicloselob -- Closes lob descriptor
ocicollappend -- Aggiunge un oggetto alla collezione
ocicollassign -- Assegna una collezione da un'altra collezione esistente
ocicollassignelem -- Assegna un elemento alla collezione in una specifica posizione
ocicollgetelem -- Coming soon
ocicollmax -- Coming soon
ocicollsize -- Coming soon
ocicolltrim -- Coming soon
ocicolumnisnull -- Verifica se un campo di risultato è NULL
ocicolumnname -- Restituisce il nome di un campo
ocicolumnprecision -- Coming soon
ocicolumnscale -- Coming soon
ocicolumnsize -- Restituisce la dimensione del campo
ocicolumntype -- Restituisce il tipo di dati di un campo
ocicolumntyperaw -- Coming soon
OCICommit -- Esegue le transazioni in sospeso
OCIDefineByName --  Utilizza una variabile PHP per la fase di definizione in un comando SELECT
OCIError -- Restituisce l'ultimo errore di stmt|conn|global
ociexecute -- Esegue un comando SQL
ocifetch -- Estrae la prossima tupla opnendola nel buffer di risultato.
ocifetchinto -- Estrae la prossima tupla ponendola in un array
ocifetchstatement -- Estrae tutte le tuple in un array
ocifreecollection -- Coming soon
ocifreecursor --  Libera tutte le risorse associate ad un cursore
ocifreedesc -- Cancella un descrittore di oggetto binario (LOB)
ocifreestatement --  Libera tutte le risorse associate ad un'istruzione
lob->getBuffering -- Returns current state of buffering for large object
ociinternaldebug --  Abilita o disabilita la visualizzazione del debug interno.
ociloadlob -- Coming soon
ocilogoff -- Disconnette da Oracle
ocilogon -- Stabilisce una connessione a Oracle
ocinewcollection -- Coming soon
ocinewcursor --  Restituisce un nuovo cursore (Statement-Handle)
ocinewdescriptor --  Inizializza un nuovo descrittore LOB/FILE vuoto
ocinlogon -- Stabilisce, una nuova connessione a Oracle.
ocinumcols --  Restituisce il numero di campi che risultano da un comando SQL
ociparse -- Analizza una query e restituisce un'istruzione.
ociplogon --  Stabilisce una connessione permanente a Oracle.
ociresult -- Restituisce il valore di campo della tupla estratta
ocirollback -- Annulla le transazioni in sospeso
ocirowcount -- Restituisce il numero di tuple modificate
ocisavelob -- Coming soon
ocisavelobfile -- Coming soon
ociserverversion -- Restituisce una stringa contenente informazioni sulla versione del server
lob->setBuffering -- Changes current state of buffering for large object
ocisetprefetch -- Imposta il numero di tuple da precaricare
ocistatementtype -- Restituisce il tipo di un'istruzione OCI
ociwritelobtofile -- Coming soon
ociwritetemporarylob -- Writes temporary blob


add a note add a note User Contributed Notes
Funzioni Oracle 8
warlock at tekops dot com
19-May-2004 02:56
regarding the above comment about modifying the apachectl script there's a better way.  Please don't take this as me being arrogant as I did it that way until just now.  Reading this same page I found that if you modify /usr/local/apache/bin/envvars or /usr/local/apache2/bin/envvars (depending on your version of apache) does the same thing the right way.  I've been using apache since 96 and I just learned this....  :) cheers.
cyrill@_malevanov_dot_spb_dot_ru
10-May-2004 07: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);
?>
gmueller (at) it4sport (dot) de
20-Apr-2004 07:55
Another fix for error message "Unable to load dynamic library 'C:/php/extensions/php_oci8.dll".
I had spaces in my system path variable. After quoting the specific path everything worked.
cyrill@_malevanov_dot_spb_dot_ru
20-Apr-2004 05:42
How to pass CLOB as a stored procedure parameter:

<?
   error_reporting
(1+2+4+8);
  
$conn = OCILogon('batdtd', 'batdtd', 'bathome');
  
$lob = OCINewDescriptor($conn, OCI_D_LOB);
  
$stmt = OCIParse($conn, "declare rs varchar2(32767); begin :rs := aaa(:par); end;");
  
$lob_data = 'abcdefgh';
   echo
"binding lob...";
  
OCIBindByName($stmt, ':par', &$lob, -1, OCI_B_CLOB);
   echo
"done<br>binding rs...";
  
$rs = '';
  
OCIBindByName($stmt, ':rs', &$rs, 32767);
   echo
"done<br>writing temp lob...";
  
$lob -> WriteTemporary($lob_data);
   echo
"done<br>executing...";
  
OCIExecute($stmt, OCI_DEFAULT);
   echo
"done<br>rs = '$rs'";
  
OCICommit($conn);
  
$lob -> free();
  
OCIFreeStatement($stmt);
  
OCILogoff($conn);
?>
Jon
10-Apr-2004 05:20
I finally figured out quite the annoying problem with a recompile of the php-4.2.2-17.2 source RPM on RedHat 9 with Oracle support.  I don't know why this worked, but perhaps it will help someone who is in the same bind:

# cd /usr/src/redhat/SPECS

You should see a file called php.spec.  Open it up in your favorite text editor and you should see some lines like this:

%if %{oracle}
       --with-oci8=shared \
%endif

Change it so that it points to your installation of the Oracle OCI libraries:

%if %{oracle}
       --with-oci8=shared,/usr/oracle/product/9.2 \
%endif

...is one example.  Make sure the "shared," portion is there, or else the make of libphp4 will not work, stating that it cannot find library clntsh.  Then, rebuild using the following command:

# rpmbuild -ba --define 'oracle 1' php.spec

Keep in mind that this does not include the fixes for openssl problems on RedHat 9, which are noted in this location: http://www.php.net/manual/en/install.linux.php.  This is something I am trying to confirm now.

I hope this helps!
k dot prisk at auckland dot ac dot nz
08-Apr-2004 01:44
Another fix for error message "Unable to load dynamic library 'C:/php/extensions/php_oci8.dll".
We had both oracle 8, and 9.2 clients installed on a windows 2000 server running IIS 5.
I found that php was looking in the 9.2 directory for an oracle 8 file (dll). Changing the system path, placing C:\oracle\ora81\bin ahead of C:\oracle\ora92\bin solved the problem.
sebastian01 at hotmail dot com
01-Apr-2004 11:39
-----------------------------------

All that I want to know I found it here:
http://www.exzilla.net/docs/php-oci8/php-plsql.php

It has a great example!!! Take a look!

-----------------------------------

Todo lo que quería saber lo encontré acá:
http://www.exzilla.net/docs/php-oci8/php-plsql.php

Tiene un muy buen ejemplo!!! Pegale una mirada!

-----------------------------------
dadarden_nospamoladude at iti2 dot net
12-Mar-2004 11: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 02: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 :)
giunta dot gaetano at sea-aeroportimilano dot it
12-Feb-2004 11:38
If OCI does not function with PHP+IIS, and you get an error message about access to php_oci8.dll being denied: "Unable to load dynamic library 'C:/php/extensions/php_oci8.dll", even though both this dll and the oracle client dlls are installed, make sure that "Allow IIS to Control Password" is unchecked in the preferences panel for anonymous user access.

For more detail on the issue, read articles 216828 and 218756 in the MS Knoweledge Base.
hboulnois at alapage dot com
04-Dec-2003 05:43
I installed PHP 4.3.4 under redhat 9 with oracle 9.2, and I had always 12154 error at login. In fact, oracle home directory (/opt/oracle) had 700 rights (this is done at creation of oracle user with redhat-config-user).
After a chmod 755 /opt/oracle all is running correctly.
mjahn at agency dot at
07-Oct-2003 05:43
Finally got php4.3.3 with OCI8 for Oracle9.2 working in apache under HP-UX 11.22 (IA64). I had a tough time achieving this, maybe somebody else finds the hints useful.

* First you need to hack the configure file, maybe thats solved by now but once it detects HP-UX it believes that you got a PA-RISC machine runnnig. I messed so much around with this file so i cant really say what helped and what not. What i did: replace all .sl to .so, changed lt_cv_deplibs_check_method to pass_all, changed dynamic linker to $host_os dld.so.

* set your Oracle Environment

* export LDFLAGS=-L$ORACLE_HOME/lib32

* ./configure --with-apache=/path/to/apache --with-oci8 --with-oracle

* when doing make install as different user(root probably) remember to set Oracle Environment and LDFLAGS

* fix environment to have the include and lib directories of php used

* i had to hack src/modules/php/libphp4.module to have $ORACLE_HOME/lib32 used

* remember to install php as static module for apache

Hope i rembered everything right and it helps.
lomax at arizona edu
25-Jul-2003 10: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"
andi
01-Jul-2003 01:29
INSTALLATION
May be trivial, but took me HOURS to find out:
You CANNOT use php_oci8.dll and php_oracle.dll extensions at the same time. Just comment one of them and voila - your webserver won't crash anymore.
lore_giver at lycos dot co dot uk
20-May-2003 05: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 'make install' ran smoothly.

I only had to add the php type in the httpd.conf (in your apache conf directory eg. /usr/local/apache/conf)..
AddType application/x-httpd-php .php
to get the php to work again...

I had to then reverse the $ORACLE_HOME/lib swop on top since php was now having problems with the 32 bit version of the library...so switched it back to 64 and my php script worked....

Hope this helps some out there with similar problems..

Cheers
claus at netmedia dot de
14-Feb-2003 01:41
I had problems with german Umlaute 'äöüÄÖÜ'. The solution was NOT to set the NLS_LANG var. When I removed it from the apachectl script all worked perfect :). The only env-Var in the script is now ORA_HOME!

Oracle8.1.7
Apache 1.3.26
PHP4.3.0

HTH
gnitesh at yahoo dot com
08-Feb-2003 11:52
Addendum to "junk at netburp dot com"'s note, rowidtochar doesn't always work fine if you are using Oracle 9i. Use

cast(rowid as varchar2(xx))

instead
09-Dec-2002 07:53
Configuring/Compiling PHP as a DSO with Oracle support from source on a Sun Solaris 8 box.  We had already installed Oracle 9.2.0 client tools.

1. Make sure the following tools are installed

   autoconf
   automake
   bison
   flex
   gcc
   make
   gzip
  
   They can be downloaded from http://www.sunfreeware.com.
  
2.  Make sure Apache is installed with DSO support.  We ran the Apache configure/compile like so:

   LIBS=-lpthread ./configure \
   --prefix=/usr/local/apache \
   --enable-module=most \
   --enable-shared=max
  
  
   make
   make install
  
3.  If you haven't already, install the Oracle client tools.
4.  Make sure the following environment variables are set correctly and are accessible by all users.  We set them in /etc/profile.

   ORACLE_HOME
   ORACLE_BASE
   NLS_LANG
   ORA_NLS33
   ORACLE_TERM
   LD_LIBRARY_PATH
  
   (technically, only $ORACLE_HOME is required, but you'll want to set the rest in order to make sure things run smoothly afterward)
  
5.  Make sure '/usr/ccs/bin' is in your path.  If not, add it.
6.  Unpack PHP source (php-4.2.3):

   gunzip php-4.2.3.tar.gz
   tar xvf php-4.2.3.tar
   cd php-4.2.3

  
7.  Run PHP configure like so :

   CC=gcc ./configure --with-apxs=/usr/local/apache/bin/apxs \
   --with-config-file-path=/etc \
   --with-mysql \
   --enable-ftp \
   --with-oci8=/path/to/ORACLE_HOME \
   --with-oracle=/path/to/ORACLE_HOME \
   --enable-sigchild
  
8.  Run make:  make
9.  Run this as root:  make install
10.  Change the LoadModule line in httpd.conf to include the fully qualified path.  For us:

   LoadModule php4_module        /usr/local/apache/libexec/libphp4.so
  
11.  Make sure the PHP files types are recognized in your httpd.conf file:

   AddType application/x-httpd-php .php
   AddType application/x-httpd-php-source .phps
  
12.  Test the configuration:

   /usr/local/apache/bin/apachectl configtest
  
   It should return "Syntax OK"
  
13.  Bounce Apache:

   /usr/local/apache/bin/apachectl restart
  
  
14.  Here's a simple PHP script to test the setup.  If you don't have access to the default tables Oracle provides, change the connections/tablenames/fields to match your setup:

   <?php

   $db_conn
= ocilogon("scott", "tiger");

  
$cmdstr = "select ename, sal from emp";
  
$parsed = ociparse($db_conn, $cmdstr);
  
ociexecute($parsed);
  
$nrows = ocifetchstatement($parsed, $results);
   echo
"Found: $nrows results<br><br>\n";

   echo
"<table border=1 cellspacing='0' width='50%'>\n";
   echo
"<tr>\n";
   echo
"<td><b>Name</b></td>\n";
   echo
"<td><b>Salary</b></td>\n";
   echo
"</tr>\n";

   for (
$i = 0; $i < $nrows; $i++ ) {
         echo
"<tr>\n";
         echo
"<td>" . $results["ENAME"][$i] . "</td>";
         echo
"<td>$ " . number_format($results["SAL"][$i], 2). "</td>";
         echo
"</tr>\n";
   }

   echo
"</table>\n";

  
?>
poulman at uponorhsdna dot com
10-Oct-2002 05:51
Re: ora-12154 errors with PHP 4.2.3, Apache 1.3.27, and Oracle 9i (client only) I had two identical set ups, one on SuSE 8.0 and one on RedHat 8.0, the SuSE worked and RedHat errored with ora-12154! For some reason, having the apache user in the oracle group worked for SuSE but did not for RedHat, I had to run the Apache service as oracle user (the one used to install oracle client). Just wanted to share this little tidbit with anyone who might be pulling their hair out like me :-). Other key things were setting the ORACLE_HOME env variable before starting Apache (I did this in the profile file).
Alberto.Grajeda.at.Bolivia
26-Sep-2002 02:42
Oracle 9i and php 4.2.x in Linux
=================================
I want to share some experience in the instalation of php-oracle in linux.

My problem was the error: "Undefined ora_logon()" or "Undefined ocilogon()". And I had configured the php with-oracle and with-oci8.

* When you compile php, the php.ini create some extensions which are dll's, but we are in linux :=|, so we have to search the modules for our plataform, by instance: php_oci8.dll for windows, in linux oci8.so (php 4.2).
* Don't forget specify the ubication of php modules in php.ini. If you specify something shared in ./configure, this must be loaded as a module.
* Restart your http server, and enjoy with php.
bradburn at kiwi dot de
24-Sep-2002 11:23
keywords: NLS_LANG, NLS_CHARACTERSET,SetEnv,putenv()

If you have tried setting the environment variables -- especially NLS_LANG -- in PHP with putenv(), and perhaps also in Apache with SetEnv, and you are still having trouble with PHP+Oracle and foriegn character sets (you get e.g. 'd' for 'ä'), try setting the environment variables in your PROFILE (e.g. under bash) BEFORE starting the Apache server once more. This finally stopped the problems we were having. For reference, set the following variables:

ORACLE_HOME
ORA_NLS33
TNS_ADMIN
TWO_TASK
CLASSPATH
LD_LIBRARY_PATH
NLS_LANG

An example would be:

NLS_LANG=GERMAN_GERMANY.WE8ISO8859P15; export NLS_LANG

Then restart Apache (see below for important note).

Our system was Sun SPARC 5.8, running Apache 1.3.26 with PHP 4.2.2, and the OCI8 API for Oracle.

One further note: restart Apache with:

  apachectl stop
  apachectl start

rather than

  apachectl restart

otherwise your environment may not be reset.

Hope this helps someone!

Ed
s917725 at mail dot yzu dot edu dot tw
18-Sep-2002 01:11
If you still have ORA-12154 failed with Apache PHP on oracle8i
check
1.edit httpd.conf the apache starter user should the same user(and group) who install oracle(oracle:oinstall)

2.make apache starter .bash_profile the same with user who install oracle
3.and restart apache and php
4.make sure
$c2 = ocilogon("scott","tiger",$db);

the $db should the same with /etc/oratab  SID

taht's all
aivarannamaa at hot dot ee
23-Aug-2002 03: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?
erabbott at NOSPAMterra dot com dot br
21-Aug-2002 10: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.
jirnbergATfh-sbgDOTacDOTat
06-Aug-2002 04: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
robert at ing dot hb dot se
08-Jul-2002 11: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)
devolver at iastate dot edu
30-May-2002 10: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
ddc at portalframework.com
14-May-2002 05: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.
morales at tj dot rs dot gov dot br
24-Apr-2002 11: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.
edahnke at consultant dot com
08-Jan-2002 06: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);
85276 at gmx dot net
08-Nov-2001 05: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);

?>
ruudb at stress dot utwente dot nl
26-Oct-2001 10: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.
ned at wgtech dot com
07-Sep-2001 06: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.
jlim at natsoft dot com dot my
23-Aug-2001 08: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
doug at redhive dot com
19-Jul-2001 08: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;
}
alexis at castanares dot com
11-Jul-2001 07: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.
jasendorf at lcounty dot com
23-May-2001 09: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.
fsegtrop at estiem dot org
22-May-2001 01: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.<br> 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.<br>
This all does not matter if you use the ISAPI mode.

Frank
siegel at siegel dot in-berlin dot de
16-Jan-2001 02: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).
junk at netburp dot com
19-Oct-2000 08: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.
dave dot mink at usa dot net
17-Oct-2000 12: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.
shmengie_2000 at yahoo dot com
03-Oct-2000 09: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
ojones at dotclick dot com
19-May-2000 01: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).

<deaggregateoci_bind_by_name>
 Last updated: Sun, 02 May 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2004 The PHP Group
All rights reserved.
This mirror generously provided by: Italia OnLine S.p.a.
Last updated: Fri May 21 04:11:23 2004 CEST