-1

I have been struggling for the last few days to get PHP to connect to an oracle DB. I have been doing this with a MAMP stack installed on a window machine (it is available for windows and ensures a uniform development stack for our team). After struggling with the common problems related to the OCI8 installation I finally got it to show in phpinfo() with the following information OCI8 PHP info section

I can also see it as an installed module using the php -m command, the options using the php --ri oci8 command, and can find the installed dll files from the oracle instant client using where oci*

It appears to be installed and I have a PATH variable linked to the instant client folder. There are no errors besides the call to undefined function in the MAMP log files.

I have not set the ORACLE_HOME, TNS_ADMIN or other oracle variables as they are not needed with the instant client libraries (my understanding)

I have uncommented the lines for the extension_dir and the extension=php_oci8_12c.dll in the php.ini file and have confirmed that I have been editing the correct file.

I have ran a simple php script in an index.php file containing the following lines

<?php
    If(function_exists('oci_connect')){
      echo 'oci_connect exists';
      $conn = oci_connect();
    }
?>

This is a simple test which should give me a warning complaining about improper parameters however the output of the script is

oci_connect exists Fatal error: Uncaught Error: Call to undefined function oci_connect() in C:\MAMP\htdocs\Oracle_Connection\index.php:16 Stack trace: #0 {main} thrown in C:\MAMP\htdocs\Oracle_Connection\index.php on line 16

I have run out of ideas on what might be wrong, none of the documentation in reference to setting up the OCI8 functionality seems to run into this issue.

Any help would be welcome. Thanks

Output from cmd

C:\Users\geoff>php -m
[PHP Modules]
bcmath
calendar
com_dotnet
Core
ctype
date
dom
filter
hash
iconv
json
libxml
mcrypt
mysqlnd
oci8
odbc
openssl
pcre
PDO
pdo_mysql
Phar
Reflection
session
SimpleXML
soap
sockets
SPL
standard
tidy
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]

C:\Users\geoff>php function_exists
Could not open input file: function_exists

C:\Users\geoff>php --ri oci8

oci8

OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.1.4
Revision => $Id: 03698b2e9b50593039b7ca292b2e3cf9eaf064b9 $
Oracle Run-time Client Library Version => 12.2.0.1.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

C:\Users\geoff>where oci*
C:\Oracle\instantclient_12_2\oci.dll
C:\Oracle\instantclient_12_2\oci.sym
C:\Oracle\instantclient_12_2\ocijdbc12.dll
C:\Oracle\instantclient_12_2\ocijdbc12.sym
C:\Oracle\instantclient_12_2\ociw32.dll
C:\Oracle\instantclient_12_2\ociw32.sym
Geoff
  • 1
  • 1
  • First off, Welcome to SO! Now, have you tried to restart the server? "Try sudo service apache2 restart" But that's not your problem. The problem is that you are calling obi_connect with no parameters! Try reading the docs :0) https://doc.bccnsoft.com/docs/php-docs-7-en/function.oci-connect.html – Native Coder Jun 06 '17 at 21:40
  • Oh, and I would DEFIANTLY reword the question, AFTER reading this: https://stackoverflow.com/help/how-to-ask Doing so will save you a lot of grief from the community in the future. They can be unforgiving at times, living by the mantra "stupid questions get stupid answers". You question is not stupid, but it does need to be....revised. – Native Coder Jun 06 '17 at 21:45
  • Try loading (via your browser) a PHP script that calls phpinfo(). You will probably find that OCI8 is missing. I suspect your web server environment is different to your command line environment: probably the Oracle client libraries are not in PATH. – Christopher Jones Jun 09 '17 at 05:09

1 Answers1

0

You are calling oci_connect() with no parameters.

Pass the username and password for your database to the function as stated in the documentation

Native Coder
  • 1,792
  • 3
  • 16
  • 34
  • -1. PHP doesn't work that way. Calling `oci_connect` without parameters should result in: `Warning: oci_connect() expects at least 2 parameters, 0 given in ...`. This shows the `oci8` module is loaded and working but you've made a mistake in how you call the function. – timclutton Jun 07 '17 at 07:28
  • That's right, I forgot about that. I just removed that portion of the answer – Native Coder Jun 07 '17 at 14:35