php8.5
Home/ Manual/ oci8 / functions/ oci_new_connect

oci_new_connect

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8, PECL OCI8 >= 1.1.0)

Connect to the Oracle server using a unique connection

Description

oci_new_connect(string $username, string $password, string|null $connection_string = null, string $encoding = "", int $session_mode = OCI_DEFAULT): resource|false

Establishes a new connection to an Oracle server and logs on.

Unlike oci_connect() and oci_pconnect(), oci_new_connect() does not cache connections and will always return a brand-new freshly opened connection handle. This is useful if your application needs transactional isolation between two sets of queries.

Parameters

username

The Oracle user name.

password

The password for username.

connection_string

Db

encoding

Charset

session_mode

Sessionmode

Return Values

Returns a connection identifier or false on error.

Changelog

VersionDescription
8.0.0, PECL OCI8 3.0.0connection_string is now nullable.

Examples

The following demonstrates how you can separate connections.

oci_new_connect() example

php
<?php

// create table mytab (mycol number);

function query($name, $c)
{
    echo "Querying $name\n";
    $s = oci_parse($c, "select * from mytab");
    oci_execute($s, OCI_NO_AUTO_COMMIT);
    $row = oci_fetch_array($s, OCI_ASSOC);
    if (!$row) {
        echo "No rows\n";
    } else {
        do {
            foreach ($row as $item)
                echo $item . " ";
            echo "\n";
        } while (($row = oci_fetch_array($s, OCI_ASSOC)) != false);
    }
}

$c1 = oci_connect("hr", "welcome", "localhost/orcl");
$c2 = oci_new_connect("hr", "welcome", "localhost/orcl");

$s = oci_parse($c1, "insert into mytab values(1234)");
oci_execute($s, OCI_NO_AUTO_COMMIT);

query("basic connection", $c1);
query("new connection", $c2);
oci_commit($c1);
query("new connection after commit", $c2);

// Output is:
//   Querying basic connection
//   1234 
//   Querying new connection
//   No rows
//   Querying new connection after commit
//   1234 

?>

See oci_connect() for further examples of parameter usage.

See Also

Source: reference/oci8/functions/oci-new-connect.xml · from the official PHP manual (php/doc-en)