oci_new_connect

Connect to the Oracle server using a unique connection

&reftitle.description; ``resource``false```oci_new_connect` `string` `username` `string` `password` ``string``null```connection_string`&null; `string` `encoding`"" `int` `session_mode` `OCI_DEFAULT`

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.

&reftitle.parameters;

`username`

- The Oracle user name.

`password`

- The password for `username`.

`connection_string`

- &oci.db;

`encoding`

- &oci.charset;

`session_mode`

- &oci.sessionmode;
&reftitle.returnvalues;

Returns a connection identifier or &false; on error.

&reftitle.changelog;

&Version; | &Description;
8.0.0, PECL OCI8 3.0.0 | `connection_string` is now nullable.

&reftitle.examples;

The following demonstrates how you can separate connections.

### `oci_new_connect` example

    <?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.

&reftitle.seealso;

- `oci_connect`
- `oci_pconnect`