Failed to connect to oci_connect

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

I tried many connection options (listed below) with the same error as when returning:

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

After googling for the whole day, I can only say that this error means that PHP was able to communicate with the server, but could not connect to a specific service / database and that the error should not come from PHP itself ...

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

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

Using this description, for example

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

I can connect to server and service / database using sqlplus console, so the connection is very correct. I also use the same HOST, PORT and SID to connect to the server using the Sqldeveloper tool. The problem is connecting to the server in PHP ...

What I have tried so far:

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

All oci_connect calls listed above return the same error.

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

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

but the problem is that I don’t know the service name , only the service ID ( SID ), so the error returned is this:

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

which says that there is no service working with the specified service name (or that the ORA listener does not know about such a service).

PHP Version: 5.3.14
Appache v.: 2.2.22 (32bit) Zend
Zend CE Server: 5.3.6

PHP information 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 

Perhaps the problem is that there is a version of unknown Oracle instant client , although the path is specified in the TNS_ADMIN and PATH environment TNS_ADMIN ...

My question is: Does anyone know what I did wrong? Am I missing something? I have googled all day yesterday, so probably (with a 99% chance) any google links that you would like to provide to me, I already saw and tried ...

Although this question can be regarded as an exact duplicate of this , it has not yet been answered, and I think that no one will return to this old question, even if I post a comment. I also have connection problems. Also keep in mind that in this similar question another error is returned and requested.

+1
source share
5 answers

Due to several incorrect configurations and 3 days lost in finding a solution, I switched to development on a Linux server and all problems disappeared.

What I found:

  • both php_oci8.dll and php_oci8_11g.dll depend on Oracle Instant Client libraries
    • these libraries do not contain oci_ functions (e.g. oci_connect ), only ociX functions (e.g. ociLogon ), which is strange ...
  • although I'm sure I downloaded Oracle Instant Client Basic and all the extensions, I could not connect to another Oracle server due to an unknown encoding, and the error was that I only use Lite instant client ...
  • I tried both the 64-bit and 32-bit client versions without changes
  • my Apache - 64-bit, 64-bit, PHP - 32-bit, remote Oracle server - 64-bit, remote Linux server - 64-bit ...
  • tried many environment settings ( ORA_HOME , TNS_ADMIN , adjusted PATH to look at instant client installation) to no avail
  • tried to remove the local Oracle XE server due to possible interference in the environment settings to no avail
  • almost lost his head - to no avail ...

So, finally on a Linux server, I have no problem connecting to a remote Oracle server. Somewhere (while browsing over a thousand PHP-Oracle-related pages) I found information that “there is no need to develop a PHP application connecting to the Oracle server under windows”, and you should stick to the UNIX system instead ...

So someone is experiencing similar or similar problems - be so kind as not to waste your time, install VirtualBox, start Linux and move forward!

+4
source

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

Step-1: Log in to db using sys as sysdba and run the following scripts.

**

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

**

Step 2: PHP script in you

**

 $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). Ensure that the PHP_OCI8 and PHP_OCI8_11g applications are enabled.

II). Oracle 11 is case sensitive.

Best regards Yasser Hashmi

+1
source

I had the same problem and tried to connect from the local machine to the remote server. after 2 weeks of training, I finally got him to work.

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

let's take a PHP example:

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

what they were not talking about is that it points to the default port on the server.

if your is set to another one you need to point out. see the new example below:

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

try this with your specified port.

Hope this helps

+1
source

Just adding my two cents since I hit my head against the wall with this ... If all else fails, try this as soon as you download the instant client, http://www.oracle.com/technetwork/topics/winsoft -085727.html , copy it to the apache / bin folder. You will probably ask to rewrite the oci.dll file. Do this, then restart apache / php. With any luck, this will fix the problem ...

Good luck.

+1
source

My solution in 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 
0
source

All Articles