简体   繁体   中英

Connecting to Oracle 18c Database with OCI8

I have set up an Oracle 18c database and am trying to connect to it from a php file but when I run a simple connection test, I receive a server error where it cant't seem to connect. I ran print_r(getLoaded_extensions()); and from the output array it shows that I am currently not using the oci8 extension as I wanted. My connection test file contains the following

#!/usr/local/bin/php
<?php
putenv("ORACLE_HOME=/usr/lib/oracle/18.3/client64")

    $db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ***.***.*.**)(PORT = 1521)))(CONNECT_DATA=(SID=orcl)))" ;

    if($c = OCILogon("username", "password", $db))
    {
        echo "Successfully connected to Oracle.\n";
        OCILogoff($c);
    }
    else
    {
        $err = OCIError();
        echo "Connection failed." . $err[text];
    }

I am unsure whether I set my putenv() wrong to the correct location of the oci.dll file or if I need to install the extension in the first place. Thank you

因为您说过您检查了当前使用的扩展名并且OCI8不存在,所以我将继续安装该模块并在您的服务器上启用它

Most probably, the 18c default installation creates a Container DB (CDB) called ORCL and PDB1 (pluggable DB).. Run lsnrctl stat to look for the services created. then, in DB connection, use service_name instead of SID for connection. The value of service_name can be seen in the output of lsnrctl stat

Example.

 $db = "(DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = patronus.domain.com)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = pdb1.domain.com)
        )
      )" ;

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