简体   繁体   中英

Connecting to Oracle using oci_connect

I am trying to make a successful Oracle connection using PHP.

Here is how my connection string looks:

<?php
   $conn = oci_connect("USER", "PASS", "LOSINGMINDHOST");
   if (!$conn) {
       $e = oci_error();
       error_log(trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR));
   }

   oci_close($conn);
?>

Getting the following error:

Warning: oci_connect(): ORA-12170: TNS:Connect timeout occurred

Which points to the line with oci_connect.

I am on a Windows Server 2019.

The php.ini file has been updated to include the following:

extension=oci8_12c

I have confirmed that the dll file above is indeed in the ext folder listed as:

php_oci8_12c.dll

Not sure why the php.ini file does not include the full name of the dll file.

The server has been installed with Ocale 12g instant client 64bit.

We have confirmed a connection using ODBC Data Source Administrator client using tnsnames.ora file.

We also have a listener.ora file the looks like this:

PROD_MIR =
 (DESCRIPTION =
  (ADDRESS_LIST =
  (ADDRESS = (COMMUNITY = ttp.world)(PROTOCOL = TTP)(Host = LOSINGMINDHOST)(Port = 1524))
  (ADDRESS = (COMMUNITY = ttp.world)(PROTOCOL = TTP)(Host = LOSINGMINDHOST)(Port = 1551))
  (ADDRESS = (COMMUNITY = ttp.world)(PROTOCOL = TTP)(Host = LOSINGMINDHOST)(Port = 1538))
)
(CONNECT_DATA =
  (SERVICE_NAME = PROD)
)
)

We added the TNS_ADMIN path to the environment variables on the server.

We have already restarted the services and even rebooted the server.

As the docs ( https://www.php.net/manual/en/function.oci-connect.php ) says:

oci_connect ( string $username , string $password [, string $connection_string [, string $character_set [, int $session_mode ]]] ) : resource

connection_string Contains the Oracle instance to connect to. It can be an » Easy Connect string, or a Connect Name from the tnsnames.ora file, or the name of a local Oracle instance.

It was your case, use the proper tnsnames.ora Connection name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM