oci_connect connection failed

 ̄綄美尐妖づ 提交于 2019-11-29 08:53:01

Due to several misconfigurations and 3 days lost while looking for a solution I moved to develop on Linux server and all of the problems are gone.

What I have found:

  • both php_oci8.dll and php_oci8_11g.dll are depending on the Oracle Instant Client libraries
    • these libraries does not contain oci_ functions (like oci_connect), only ociX functions (like ociLogon) which is strange...
  • though I am pretty sure I have downloaded Oracle Instant Client Basic and all of the extensions, I was not able to connect to another Oracle server due to unknown charset and the error was saying I am using only Lite instant client...
  • I tried both 64bit and 32bit instant client version at no avail
  • my Apache is 64bit, windows is 64bit, PHP is 32bit, remote Oracle server is 64bit, remote Linux server is 64bit...
  • tried many environment settings (ORA_HOME, TNS_ADMIN, adjusted PATH to look to instant client installation) at no avail
  • tried uninstalling local Oracle XE server due to possible environment settings interference at no avail
  • almost lost my head - at no avail...

So finaly on Linux server I have no problems connecting to remote Oracle server. Somewhere (while surfing over thousands of PHP-Oracle related pages) I have found an information that "one shouldn't develop PHP application connecting to Oracle server under windows" and should stick to UNIX system instead...

So anybody experiencing similar or same problems - be so kind and do not waste Your time, install a VirtualBox, run Linux on it and move forward!

to connect php to Oracle 11g version 11.2 you need to do following;

Step-1: login to you db with sys as sysdba and execute following scripts.

**

execute dbms_connection_pool.start_pool();
execute dbms_connection_pool.restore_defaults();

**

Step-2: in you PHP script

**

$conn = oci_connect("username", "password", "//hostname/servicename");
if (!$conn) {
   $m = oci_error();
   echo $m['message'], "\n";
   exit;
}
else {
   print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);

**

Note: i). Make sure PHP_OCI8 and PHP_OCI8_11g exertions are enabled

ii). Oracle 11 is case sensitive.

Best Regards Yasir Hashmi

I have had the same issue and tried to connect from my local machine to a remote server. after 2 weeks of tring I finally got it to work.

the solution is very simple but not documented in the PHP documentation

so let us take the sample PHP provided:

$conn = oci_connect('hr', 'welcome', 'localhost/XE');

what they did not mention is that it points to the default port on the server.

if yours is set up to a different one you need to specify that. see the new example below:

$conn = oci_connect('hr', 'welcome', 'localhost:1234/XE');

try that with your specified port.

Hope this helps

Just adding my two cents, as I Banged my head against the wall with this one... If all else fails, try this, Once you have downloaded the instant client, http://www.oracle.com/technetwork/topics/winsoft-085727.html, copy it's extracted contents to the apache/bin folder. It'll likely ask you to over-write the oci.dll. Do so, then restart apache/php. With luck this will fix the problem...

Good luck.

My solution on fedora 17:

1. yum install httpd httpd-devel.
2. yum install php php-mysql php-pear php-devel
3. Install oracle instantclient:

rpm -Uvh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm 
rpm -Uvh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm 

4. pecl install oci8

This gives:

**
downloading oci8-1.4.7.tgz ...
Starting to download oci8-1.4.7.tgz (Unknown size)
.....done: 168,584 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
Please provide the path to the ORACLE_HOME directory.
Use 'instantclient,/path/to/instant/client/lib' if you're compiling
with Oracle Instant Client [autodetect] :' 
** 

Just press enter.

5. Enable the OCI8 extension by creating a file, oci8.ini for example, with the following line at /etc/php.d/:

extension=oci8.so

6. service httpd restart
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!