Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
492 views
in Technique[技术] by (71.8m points)

php - oci_connect connection failed

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...