note 98431 added to function.oci-connect
| From: | JonathonRobinson at osu1 dot php dot net | Date: | Tue, 15 Jun 2010 18:12:09 +0000 |
| Subject: | note 98431 added to function.oci-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170145@lists.php.net to get a copy of this message | ||
"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:
$dbh = oci_connect($username, $password, $conn_info);
// Do stuff
$dbh = oci_connect$username, $password, $conn_info);
// Do more stuff
The follow code will generate *two* connection handles:
getData();
// Do stuff
getData();
// Do more stuff
getData() {
$dbh = oci_connect($username, $password, $conn_info);
// Do stuff
}
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:
getData($username, $password, $conn_info) {
$dbh = oci_connect($username, $password, $conn_info);
$key = hash('md5', "$username|$password|$conn_info");
$GLOBALS[$key] = $dbh;
// Do stuff
}
I originally logged this as a bug but apparently this is the expected behaviour, likely because
oci_close($dbh) just calls unset($dbh).
----
Server IP: 69.147.83.197
Probable Submitter: 208.65.73.103
----
Manual Page -- http://www.php.net/manual/en/function.oci-connect.php
Edit -- https://master.php.net/note/edit/98431
Del: integrated -- https://master.php.net/note/delete/98431/integrated
Del: useless -- https://master.php.net/note/delete/98431/useless
Del: bad code -- https://master.php.net/note/delete/98431/bad+code
Del: spam -- https://master.php.net/note/delete/98431/spam
Del: non-english -- https://master.php.net/note/delete/98431/non-english
Del: in docs -- https://master.php.net/note/delete/98431/in+docs
Del: other reasons-- https://master.php.net/note/delete/98431
Reject -- https://master.php.net/note/reject/98431
Search -- https://master.php.net/manage/user-notes.php