1

I'm trying to connect to an Oracle database using PHP using the following code:

$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. Is there a way to do that?

1 Answer 1

1

The preferred solution is to use an Oracle wallet, doing "External Authentication". See p116 of Oracle's free The Underground PHP and Oracle Manual.

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you also share the second alternative? The first alternative is good but it's kinda complicated to do in our current set up so I'm looking for other ways.
The environment variable solution depends on what webserver and OS you are running on, and how you want to start PHP. There are plenty of resources on the web that will help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.