简体   繁体   English

使用OCI8连接到Oracle 18c数据库

[英]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. 我已经建立了一个Oracle 18c数据库,并试图从一个php文件连接到它,但是当我运行一个简单的连接测试时,我收到一个服务器错误,它似乎无法连接。 I ran print_r(getLoaded_extensions()); 我跑了print_r(getLoaded_extensions()); and from the output array it shows that I am currently not using the oci8 extension as I wanted. 从输出数组中可以看到,我目前未按需要使用oci8扩展名。 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. 我不确定是否将我的putenv()错误设置为oci.dll文件的正确位置,或者是否需要首先安装扩展名。 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. 最可能是18c默认安装会创建一个名为ORCL和PDB1(可插拔DB)的容器数据库(CDB)。运行lsnrctl stat查找所创建的服务。 then, in DB connection, use service_name instead of SID for connection. 然后,在数据库连接中,使用service_name而不是SID进行连接。 The value of service_name can be seen in the output of lsnrctl stat 在lsnrctl stat的输出中可以看到service_name的值

Example. 例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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