Regarding the following statement in the documentation:
"The second and subsequent calls to oci_connect() with the same parameters will return the connection handle returned from the first call."
There's one caveat here. Subsequent calls to oci_connect() will only return the same connection handle as the first call as long as a reference is held to the original handle.
For example, the following code will generate *one* connection handle:
<?php
$dbh = oci_connect($username, $password, $conn_info);
$dbh = oci_connect$username, $password, $conn_info);
The follow code will generate *two* connection handles:
getData();
getData();
getData() {
$dbh = oci_connect($username, $password, $conn_info);
}
?>
This is the result of PHP garbage collecting the handle at the end of the method scope.
If you want to isolate your DB layer through function calls but still want to leverage the fact that oci_connect can return the same handle, just keep a reference to the handle like so:
<?php
getData($username, $password, $conn_info) {
$dbh = oci_connect($username, $password, $conn_info);
$key = hash('md5', "$username|$password|$conn_info");
$GLOBALS[$key] = $dbh;
}
?>
I originally logged this as a bug but apparently this is the expected behaviour, likely because oci_close($dbh) just calls unset($dbh).