Fonctions Oracle (PDO_OCI)


Si la base de donnée Oracle est sur la même que PHP, le logiciel de base de donnée contient déjà les bibliothèquess nécessaire. Quand PHP est sur une machine différente, utilisez les biliothèques gratuites » Oracle Instant Client. Pour plus de détails consultez la section sur Prérequis OCI8.

Utilisez l'option de compilation --with-pdo-oci[=DIR] pour installer l'extension PDO Oracle OCI, où [=DIR] (optionnel) représente le chemin vers le dossier racine d'Oracle. [=DIR] vaut par défaut la valeur de la variable d'environnement $ORACLE_HOME.

Utilisez l'option --with-pdo-oci=instantclient,prefix,version pour leOracle Instant Client SDK, où le préfixe et la version sont configurés.

// Utilisation de $ORACLE_HOME
$ ./configure --with-pdo-oci

// Utilisation de OIC pour Linux avec RPMs avec le préfixe /usr
$ ./configure --with-pdo-oci=instantclient,/usr,

Constantes pré-définies

Les constantes ci-dessous sont définies par ce pilote et seront seulement disponibles lorsque l'extension aura été compilée dans PHP ou chargée dynamiquement du moteur d'exécution. De plus, ces constantes spécifiques au pilote devraient être utilisées seulement si vous utilisez ce pilote. En utilisant les attributs spécifiques à un pilote avec un autre pilote pourrait causer un comportement inattendu. PDO::getAttribute() pourrait être utilisé pour obtenir l'attribut PDO::ATTR_DRIVER_NAME pour vérifier le pilote, si votre code peut fonctionner sur des pilotes multiples.


Fournit un moyen de spécifier l'action sur la session de base de données.

Existe à partir de PHP 7.2.16 et 7.3.3


Fournit un moyen de spécifier l'information du client sur la session de base de données.

Existe à partir de PHP 7.2.16 et 7.3.3


Fournit un moyen de spécifier l'identifiant de client sur la session de base de données.

Existe à partir de PHP 7.2.16 et 7.3.3


Fournit un moyen de spécifier le module sur la session de base de données.

Existe à partir de PHP 7.2.16 et 7.3.3


add a note

User Contributed Notes 14 notes

Wolfgang Riedmann
1 year ago
An important hint: if you are using prebuilt PHP packages where PDO_OCI is not compiled in, you should download the original PHP sources for the PHP version your server is using.
These sources contain the PDO_OCI source in the ext/pdo_oci directory.
Change to that directory, build the module using
and then install the newly build module to your PHP extension directory and add it to your configuration.
For me this has worked on a Debian server with the modules (PHP 8.2).
php at ideacode dot com
12 years ago
If you're getting the "I'm too dumb to find oci.h" error, try creating a variety of paths. One variety uses just the major and minor of your OIC version (eg, 11.2 for and another variety uses client64 as well as client.

Something like this (for
ln -s /usr/include/oracle/ /usr/include/oracle/11.2
ln -s /usr/include/oracle/11.2/client /usr/include/oracle/11.2/client64
ln -s /usr/lib/oracle/ /usr/lib/oracle/11.2
ln -s /usr/lib/oracle/11.2/client /usr/lib/oracle/11.2/client64

This should cover your bases for 64-bit systems, as well as PHP patched to use the major.minor version number only. See also PHP bug #44989.
cursade at hotmail dot com
18 years ago
if oracle and oracle instant client has been installed,
without db in the same host

appent your instant client path and client/lib path to it,

For windows set PATH like this

After set the path ,set TNS_ADMIN everioment ,point to
where tnsnames.ora located.

Then,you can use service name to connect to your Database

Test coding

= $_POST;
$db_username = "youusername";
$db_password = "yourpassword";
$db = "oci:dbname=yoursid";
$conn = new PDO($db,$db_username,$db_password);
$name = $param['module'];
$file = $param['file'];
$stmt = $conn->exec("INSERT INTO AL_MODULE (AL_MODULENAME, AL_MODULEFILE) VALUES ('$name', '$file')");

fernando dot wendt at gmail dot com
15 years ago
To enable PDO support on PHP for Oracle Instant Client 11.1.x, you should follow the syntax above in the compile command, just as pointed by Andrew, taking by default you have installed the OIC at /usr/lib/oracle (instant client and sdk at subfolder):

./configure --with-oci8=shared,instantclient,/usr/lib/oracle

Just saying your release version from the Oracle OIC.

It compiles fine then.

Best regards.
geompse at gmail dot com
13 years ago
Notice the red block at the beginning of this page... pdo_oci is HIGHLY experimental.

Even though it is under dev from 2004, it lakes today support for things that _do_ matters :
- bind a varchar2 of 3500 chars
- get selected metas
- left join with blobs/clobs
- etc.

For the story, since we use pdo_pgsql in our software, I thought it would be viable to use pdo_oci for running under Oracle. After a long battle, I finally won :

1) If requested driver has a non-experimental pdo version available, use it.
2) else (well, for pdo_oci at least), use an abstraction layer of your own.
3) you're done.

What I did in more details...

2 "main" classes for being compliant with "$obj instanceof PDO" or such :
- class PhpDb extends PDO
- class PhpDbStatement extends PDOStatement
2 "abstract" classes that defines what PDO actually does :
- abstract class PhpDbAbstract
- abstract class PhpDbAbstractStatement
And at last for each driver, 2 classes doing the abstraction :
- class PhpDbDriverOracle extends PhpDbAbstract
- class PhpDbDriverOracleStatement extends PhpDbAbstractStatement

"main" classes are accessed from your script, simply replace "new PDO" with "new PhpDb".
"abstract" classes are mainly there for the documentation :p
"driver" classes do the job in background, they are instances by the main classes.

My PhpDb will be in an open source project sooner or later, search google or mail me !
cursade at hotmail dot com
18 years ago
If instant client has been installed but the full oracle client
not yet ,you can use pdo to connect to oracle database
like following coding:

= "
(ADDRESS = (PROTOCOL = TCP)(HOST = yourip)(PORT = 1521))
$db_username = "youname";
$db_password = "yourpassword";
$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
PDOException $e){
echo (
redlorry919 at gmail dot com
13 years ago
Take note of the note at the top, this really is an experimental extension. I had a problem trying to read data from Oracle which resulted in some strange behaviour in PHP. i.e. foreach loops not ending, with no error messages. I also managed to get the data from Oracle into an array in PHP, but then couldn't return the array from a function.

After pulling my hair out for a day, it turned out to be a CLOB column in Oracle that caused the strange behaviour in PHP. I assume this extension doesn't fully support them.

Instead I've typecast it within the SQL to a VARCHAR2 which seems to resolve it:

SELECT CAST(columnx AS VARCHAR2(4000)) AS columnx ...

It might help someone else having similar issues.
18 years ago
A Statement of Warning:

PDO::oci does not support REF CURSORS.

This is mentioned nowhere (until now!) on this page.

And now you know!

If you want ref cursors avoid PDO for now.

My Reference for this claim:

GREAT article, excellent piece, really. It's not clear to me
how old this document is, but it must have some dust on it,
given it's references to "PHP5.1 ...' which is a little way off yet' "
... as of 2006-06-01, PHP5.1 has been with us for quite some time.
ken at xpressconnex dot com
16 years ago
Wow, cursade. That's a lot of typing to use the lite client.

Try this:

$db = '//hostname/servicename'; //e.g. '//'
$user = 'username';
$pass = 'password';

$conn = new PDO($db,$user,$pass);
sixd at php dot net
14 years ago
From the PHP 5.3 UPGRADING file:

- The PDO_OCI php_pdo_oci8.dll library (for use with Oracle version 8 client
libraries) is no longer being built [with PHP 5.3]. Instead, use php_pdo_oci.dll (note no
'8') with Oracle 10 or 11 client libraries. Connection to other database
versions is still supported.
wagner dot lague at gmail dot com
7 years ago
Whe I try connect the server returns the error: "SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12560: TNS:erro de adaptador de protocolo (ext\pdo_oci\oci_driver.c:579)"

Too fix it, I used that:

$conn = new PDO("oci:dbname=DBNAME;host=NN.NN.NN.NNN",'USER','PASSWORD');


$conn = new PDO("oci:dbname=DB_FOO;host=",'FOO','Foo%&5b');
av01 at bugfix dot cc
14 years ago
In order to get this compiled on my CentOS 5.4 x86_64 box, I had to do some extra settings that might be useful for others:

Install oracle-instantclient11.2-basic and oracle-instantclient11.2-devel RPMs from Oracle

Create some symbolic links because configure contains some outdated assumptions about path names and doesn't care about 64-bit systems:
ln -s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client
ln -s /usr/include/oracle/11.2/client64 /usr/lib/oracle/11.2/client/include

Add the following to your configure command:
sebastian dot la dot spina at gmail dot com
10 years ago
For Red hat 6, 64bits, client 11.2,
After touch config.m4 and tune up libs symlinks..
I get a compilation error "pdo_oci.c:34: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pdo_oci_functions’"
To solve it just change function_entry to zend_function_entry @pdo_oci.c file.

paul dot pratt at atmel dot com
11 years ago
Is PHP-to-Oracle much slower than Php-to-MySql ? I have battled my way through a conversion of Php4/MySql to Php5/Oracle (stumbling over Clobs and php5-variable-initialization). Everything works, but...
Querys that took 8 seconds in MySql, now take 3 mintues with Oracle. Yes, I have indexes on the Oracle tables. Are Oracle connections that much more expensive than MySql? I did use oci_pconnect.
To Top