9

I have a simple php script:

<?php
$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:

MYSID =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = myhost.net)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = MYSERVICE)
    )
  )

I have also downloaded SQLDeveloper from http://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html

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 11.2.0.3.0 

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

EDIT:

I have tried the various suggestions in other posts on stackoverflow, namely:

extension=oci8.so with and without extension=php_oci8_12c.dll

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

EDIT:

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

Loaded Configuration File => C:\php5.6.6\php.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-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo"

EDIT:

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

EDIT:

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

Graham
  • 7,807
  • 20
  • 69
  • 114
  • 1
    Please check the link:- http://stackoverflow.com/questions/22478387/call-to-undefined-function-oci-connect. (second answer). Or http://stackoverflow.com/questions/8635881/fatal-error-call-to-undefined-function-oci-connect. (first answer) – Alive to die - Anant Mar 25 '15 at 14:06
  • 1
    Check if you have a copy of `msvcr71.dll` somewhere in your path. – timclutton Apr 08 '15 at 05:10
  • It wasn't - is now - made no difference – Graham Apr 08 '15 at 08:03
  • 1
    What's the result of running `php --ri oci8` at the command prompt? If you could provide the package name (or download links) of PHP and the instantclient you are using I'll trying to reproduce the problem. – timclutton Apr 08 '15 at 12:04
  • `php --ri oci8` gives me `Extension 'oci8' not present` – Graham Apr 08 '15 at 12:15
  • instant client from this page http://www.oracle.com/technetwork/topics/winsoft-085727.html - Version 12.1.0.2.0 – Graham Apr 08 '15 at 12:20
  • php download from this page http://windows.php.net/download#php-5.6 - VC11 x86 Non Thread Safe - originally downloaded 5.6.6, but that isn't on that page anymore. I have also tried it with 5.6.7 - makes no difference. – Graham Apr 08 '15 at 12:23
  • Sorry - I had commented out the `extension=php_oci8_12c.dll` lines as they weren't working. `php --ri oci8` now gives me `Warning: PHP Startup: Unable to load dynamic library 'C:\php\ext\php_oci8_12c.dll' - %1 is not a valid Win32 application.in Unknown on line 0. Extension 'oci8' not present` Same happens for `php_oci8.dll` and `php_pdo_oci.dll` – Graham Apr 08 '15 at 12:53

2 Answers2

12

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 php-5.6.7-nts-Win32-VC11-x86.zip).
  • Download and extract InstantClient (I used C:\instantclient_12_1 from instantclient-basic-nt-12.1.0.2.0.zip).
  • Add the above paths to the system path.
  • Copy c:\php\php.ini-production to c:\php\php.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

OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.9
Revision => $Id: f5a3ee1083d1ffa6adb5143efda6eafa210b8414 $
Oracle Run-time Client Library Version => 12.1.0.2.0
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
oci8.events => 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'));"
bool(true)
timclutton
  • 12,682
  • 3
  • 33
  • 43
  • As you have taken the effort to try and reproduce my problem, the least I can do is try a clean install and see what happens - renamed my php and instant client folders - renamed registry entry - downloaded the files again - uninstalled the VC++ runtimes - followed your instructions - I was really hopeful - at least this time I get a different error message when I run `php --ri oci8` - oci.dll missing. Copied oci.dll from renamed folder to c:\php - now back to square one - one other point - I had to add the line `extension=php_oci8_12c.dll` rather than enable it - thanks for trying – Graham Apr 08 '15 at 13:49
  • Where did you get your VC++ runtimes from - that's the only thing left that might be different? – Graham Apr 08 '15 at 14:54
  • 1
    I'm confused as to why you'd need to copy `oci.dll` to the PHP folder. As long as the paths are set correctly it should 'just work'. `oci.dll` depends on the other files in the instantclient folder so just copying it to the PHP folder won't work. – timclutton Apr 08 '15 at 14:57
  • 1
    I use this [MS support](http://support.microsoft.com/en-gb/kb/2977003) page to find the latest VC runtime versions. – timclutton Apr 08 '15 at 14:59
  • The unzipping of the instant client created a sub folder called the same name - got rid of my copied oci.dll as the real one is now in the path - checked previous install - I had already moved that sub folder up. The two checks are now working. I have know idea why it didn't work before, but thank you for your time and effort - gotta get all the other stuff working again now :-) you have made my week. – Graham Apr 08 '15 at 15:11
  • 1
    Great, glad I could help. Good luck with the rest! – timclutton Apr 08 '15 at 15:17
  • Need your help for this : http://stackoverflow.com/questions/33893407/oci-connect-issue-at-windows-server-2012-with-php-version-5-6-14 – Muhammad Muazzam Nov 25 '15 at 13:52
  • Thank you very much for the above info! I had to reboot my Windows 2008 server after making various changes, since I had another install of an older PHP version. I had to check my `phpinfo()` to verify all my changed paths were correct which got corrected after the reboot. Just trying to be helpful in case someone runs into problems. – Alvin Bunk Nov 25 '15 at 23:54
2

In addition to what was said to fix the problem, I would like to add the php CLI side of things, as some people need to run OCI-enabled applications in CLI mode. In my case, I had to copy an instance of oci.dll into the wamp/bin/php/php<version>/ folder for php --ri oci8 to show that oci8 was correctly loaded. That doesn't prove that other files were not needed to correctly run a full-fledged application (see my technical footnote). Including the path to the instantclient 12 distribution wouldn't do it.

Technical notes: My environment being: Windows 7 + WAMP3 (php 5.6.15, apache 2.4.17), I was, after a number of experiments, able to narrow down the minimal set of three files that needed to be copied to the bin directory (Apache's for non-cli apps) from the instantclient 12 distribution, to allow instantiate an Oracle adapter within Zend Framework, perform an SQL query and read the recordset.

This set is: oci.dll, oraociei12.dll and orans.dll.

In particular, copying just oci.dll wouldn't allow the application to work (unknow Exception raised)

Fabien Haddadi
  • 1,814
  • 17
  • 22