Asked  7 Months ago    Answers:  5   Viewed   63 times

I have a simple php script:

$db_user = 'myusername';
$db_pass = 'mypassword';
$db_sid = 'mysid';
$conn = oci_connect( $db_user, $db_pass, $db_sid );

When I run it (from a browser or from the command line), I get the error:

Call to undefined function oci_connect

I'm using php 5.6.6 which came with php_oci8_12c.dll already there.

I have extension=php_oci8_12c.dll in my php.ini

I have installed instant client (12.1) - tried 32 bit version AND 64 bit version

I have ORACLE_HOME and TNS_ADMIN environment variables pointing at the instant client folder ( C:instantclient_12_1 ).

I also have C:instantclient_12_1 in my path

I have a tnsnames.ora in that same folder with this relevant entry in it:

    (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))

I have also downloaded SQLDeveloper from

SQLDeveloper works, recognizes the above mentioned tnsnames.ora and connects and successfully runs a query on the same database that my php script is trying to access.

I have spent several hours over several days trying different things to no avail.

I'm using:

php 5.6.6
windows 8.1
IIS (so no answers involving apache please)
cmd (run as administrator)
Oracle Database 11g Enterprise Edition 

Some other information that might prove useful:

I would ideally like to use oci 1.4.10 to match the production server, but not too worried about that for now.

pear install oci8-1.4.10.tgz

gives me this error:

The DSP oci8.dsp does not exist

I can't find any explanation on that error that means anything to me.

What am I missing - can anyone help me


I have tried the various suggestions in other posts on stackoverflow, namely: with and without extension=php_oci8_12c.dll

I don't have the line extension=php_oracle.dll in my php.ini file


phpinfo tells me that I am using the correct php.ini file:

Loaded Configuration File => C:php5.6.6php.ini

This line from phpinfo might also be of use:

Configure Command => cscript /nologo configure.js  "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=c:php-sdkoraclex86instantclient_12_1sdk,shared" "--with-oci8-12c=c:php-sdkoraclex86instantclient_12_1sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo"


It seems that dsp files are VC++ project files - I am now venturing on learning how to create a php extension, and hopefully when I've done that I'll have enough knowledge to compile the oci8 1.4.10 source code into a dll that works on windows 8 - unless somebody rescues me with the answer to this question - this looks like it is going to take me some time :-)


Adding display_startup_errors = On to php.ini tells me that the oci dll is not a valid Win32 application



Edit: Hmm. Trying this on Windows 8 appears to generate the same error as you specified. I'm currently investigating...

My mistake (I had enabled the wrong extension_dir line). It works in Win8 just as documented below.

The following steps should be all you need to get OCI working with PHP (I've just verified this on a freshly installed Windows 2008 R2 Standard x64 virtual machine):

  • Download and extract PHP (I used C:php from
  • Download and extract InstantClient (I used C:instantclient_12_1 from
  • Add the above paths to the system path.
  • Copy c:phpphp.ini-production to c:phpphp.ini.
  • in php.ini:
    • enabled line extension_dir = "ext".
    • enabled line extension=php_oci8_12c.dll.
  • Install Microsoft Visual C++ 2010 Runtime (x86). This is needed for the OCI8 extension.
  • Install Microsoft Visual C++ 2012 Runtime (x86). This is needed for PHP.

At this point running php --ri oci8 in a command prompt shows me the following output:

C:>php --ri oci8


OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.9
Revision => $Id: f5a3ee1083d1ffa6adb5143efda6eafa210b8414 $
Oracle Run-time Client Library Version =>
Oracle Compile-time Instant Client Version => 12.1

Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value => Off => Off

Statistics =>
Active Persistent Connections => 0
Active Connections => 0

And checking for the oci_connect function:

C:>php -r "var_dump(function_exists('oci_connect'));"
Wednesday, March 31, 2021
answered 7 Months ago

After looking at your phpinfo() output, it appears the mysql extensions are not being loaded. I suspect you might be editing the wrong php.ini file (there might be multiple copies). Make sure you are editing the php file at C:phpphp.ini (also check to make sure there is no second copy in C:Windows).

Also, you should check your Apache logs for errors (should be in the logs directory in your Apache install.

If you haven't read the below, I would take a look at the comments section, because it seems like a lot of people experience quirks with setting this up. A few commenters offer solutions they used to get it working.

Another common solution seems to be to copy libmysql.dll and php_mysql.dll from c:PHP to C:WindowsSystem32.

Wednesday, March 31, 2021
answered 7 Months ago

It seems to me that Oracle is not interested in developing a driver for PDO it's developing it's own driver to keep you close to oracle database... to oracle driver... etc. :)

As far as I've seen there is no problem if you can cope with max. texts of VARCHAR2 of 4000 CHARS. If you need CLOBs (and/or bigger) don't go with PDO_OCI.

I've created a suite of classes "PDOSurrogate" as a drop in replacement for PDO with Oracle. When PDO is mature enough I can use Refactor->Rename to change it to PDO.

Wednesday, March 31, 2021
answered 7 Months ago

You are getting startup errors for the OCI8 extension indicating that you are using an unsupported dll for your php version. You need to use the correct one, which - for PHP 5.6.x - is one of these:


You need to take the one that matches your architecture (x86 or x64), compiler (vc 9, 11, 14) and thread-safe (ts) or non-thread-safe (nts) php version, e.g. if you are running a thread-safe PHP 5.6.24 compiled with vc11 on an x86, you'd use
-------- ----- --- -- ---- --- ---
^        ^     ^   ^  ^    ^   ^
|        |     |   |  |    |   _____ extension
|        |     |   |  |    _________ architecture
|        |     |   |  ______________ compiler
|        |     |   _________________ thread-safety mode
|        |     _____________________ php version
|        ___________________________ extension version
____________________________________ extension name

If there is no download matching your PHP, then it does not exist and you need to compile it yourself. More info at

On a side note: in addition to the above, you can only use one oci extension at a time. You got both (php_oci8.dll and php_oci8_11g.dll). Make sure to remove the one you don't need.

Wednesday, March 31, 2021
answered 7 Months ago

There is no way to do what you're asking globally short of modifying php/oci-extension source code. The reason for this behavior is because oracle oci omits 0s in results and php converts all results from oci to strings without performing any casting depending on column datatype. Even results in SQL*Plus omit 0 by default, and SQL*Plus formatting has to be invoked with set numformat to customize column formatting and prepend 0s.

There is currently no alter session parameter you can set to change this behavior.

Most common way to work around this is to use a wrapper around your queries and check for numeric columns with is_numeric and then format the numeric column values with number_format or sprintf. Hopefully your application already uses a wrapper around stock php oci functions so you can make the change in one location.

Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :