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

oci_pconnect

PHP function Edit on GitHub ✎

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

Connect to an Oracle database using a persistent connection

Description

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

Creates a persistent connection to an Oracle server and logs on.

Persistent connections are cached and re-used between requests, resulting in reduced overhead on each page load; a typical PHP application will have a single persistent connection open against an Oracle server per Apache child process (or PHP FPM process). See the OCI8 Connection Handling and Connection Pooling section for more information.

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.

Examples

Basic oci_pconnect() Example using Easy Connect syntax

php
<?php

// Connects to the XE service (i.e. database) on the "localhost" machine
$conn = oci_pconnect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, 'SELECT * FROM employees');
oci_execute($stid);

echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";

?>

See oci_connect() for further examples of parameter usage.

Notes

Note

The lifetime and maximum number of persistent Oracle connections per PHP process can be tuned by setting the following configuration values: oci8.persistent_timeout, oci8.ping_interval and oci8.max_persistent.

See Also

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