oci_connect connection failed

China☆狼群 提交于 2019-12-18 05:24:10

问题


I am having serious problem connecting to external ORA DB 11g from local Zend server CE. OCI8 is enabled and running version 1.4.6 (due to phpinfo()).

I have tried many connection options (listed below) with the same error returned:

oci_connect(): ORA-28547: connection to server failed, probable Oracle Net admin error

After googling for whole day I am only able to say that this error means that PHP was able to comunicate with the server but was unable to connect to a concrete service/database and that the error shouldn't come from PHP itself...

I have set environment variable TNS_ADMIN to c:\oracle_instantclient_11_2 where the file tnsnames.ora is located containing this connection description:

MYDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = X.X.X.X)(PORT = 1521))
    )
    (CONNECT_DATA = (SID = MYDB)(SERVER = DEDICATED))
  )

Using this description like

(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=X.X.X.X)(PORT=1521)))(CONNECT_DATA=(SID=MYDB)(SERVER=DEDICATED)))

I am able to connect to the server and the service/database with sqlplus console, so the connection is very right. I am also using the very same HOST, PORT and SID to connect to the server with Sqldeveloper tool. The problem is when connecting to the server within a PHP...

What have I tried so far:

oci_connect("user", "password", "X.X.X.X:1521", "AL32UTF8", 0);
oci_connect("user", "password", "MYDB", "AL32UTF8", 0);
oci_connect("user", "password", "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=X.X.X.X)(PORT=1521)))(CONNECT_DATA=(SID=MYDB)(SERVER=DEDICATED)))", "AL32UTF8", 0);

All of these oci_connect calls above return the same error mentioned.

I had also tried the ezconnect way for 11g as stated here - [//]host_name[:port][/service_name][:server_type][/instance_name]:

oci_connect("user", "password", "X.X.X.X:1521/MYDB", "AL32UTF8", 0);

but the problem is I do not know the service name, only the service ID (SID), thus the error returned is this:

oci_connect(): ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

that says there is no service running with the service name provided (or that the ORA listener does not know of such service).

PHP version: 5.3.14
Appache v.: 2.2.22 (32bit) Zend
Zend server CE: 5.3.6

PHP info for OCI8:

OCI8 Support                   enabled
Version                        1.4.6
Revision                       $Revision: 313688 $
Active Persistent Connections  0
Active Connections             0
Oracle Instant Client Version  Unknown
Temporary Lob support          enabled
Collections support            enabled

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

Maybe the problem is that there is unknown version of Oracle instant client though it's path is set within both the TNS_ADMIN and PATH environment variables...

My question is: does anybody know of what have I done wrong? Am I missing something? I have googled for a whole day yesterday so probably (with 99% chance) any google links You would like to provide me with I have already seen and tried...

Though this question could be considered as an exact duplicate of this one - it has not been yet answered and I guess nobody will return back to that old question even if I post a comment I am having the connection problems too. Also keep in mind that in that similar question a different error is returned and asked about.


回答1:


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!




回答2:


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




回答3:


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




回答4:


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.




回答5:


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


来源:https://stackoverflow.com/questions/14646007/oci-connect-connection-failed

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