简体   繁体   English

使用 PHP 连接到 Oracle DB

[英]Connecting to Oracle DB using PHP

I'm trying to connect to an Oracle database using PHP using the following code:我正在尝试使用以下代码使用 PHP 连接到 Oracle 数据库:

$username = 'my_username';
$password = 'my_password';
$environment = 'my_environment';
// CHANGE HOST, PORT, SID
$tns = "
(DESCRIPTION =
     (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = TCP)(HOST = my_host)(PORT = my_port))
     )
     (CONNECT_DATA =
          (SID = my_sid)
     )
)
";

$conn = oci_connect($username, $password, $tns);

if (!$conn) {
   $e = oci_error();
   trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

It is working fine.它工作正常。 But what I want to do is connect without exposing the username and password in plain text.但我想要做的是连接而不以纯文本形式公开用户名和密码。 Like in Postman where you can use Basic authentication header instead of plain text.就像在 Postman 中一样,您可以使用基本身份验证标头而不是纯文本。 Is there a way to do that?有没有办法做到这一点?

The preferred solution is to use an Oracle wallet, doing "External Authentication".首选的解决方案是使用 Oracle 钱包,执行“外部身份验证”。 See p116 of Oracle's free The Underground PHP and Oracle Manual .请参阅 Oracle 免费的The Underground PHP and Oracle Manual 的 p116

Once the wallet is set up your code would look like:设置钱包后,您的代码将如下所示:

$c = oci_connect("/", "", $tns, null, OCI_CRED_EXT);

An lesser alternative is to pass the password in from an environment variable.一个较小的选择是从环境变量传递密码。

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

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