Multiple Pear DB-connections
| From: | Trond Arve Nordheim | Date: | Tue, 14 May 2002 15:14:55 +0000 |
| Subject: | Multiple Pear DB-connections | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-1370@lists.php.net to get a copy of this message | ||
Hi!
I'm writing a web system that has a separate user and content-database,
and I just discovered some problems with two multiple Pear
DB-connections at once.
I have a function that establishes the connection, and returns the
connection handle. At the top of my script, I establish the two
connections:
$dbh = db_connect();
$user_dbh = db_connect("user");
I can confirm from debugging in the db_connect()-function that it
actually establishes the correct connections, but when I attempt a query
on the $dbh-object, the query gets performed on the user database. If I
switch the two lines of code above, all user database queries are
performed on the content database.
Here is the code of the db_connect-function:
function db_connect($type = "data") {
global $content_connstring, $user_connstring;
$dbh = 0;
if ($type == "data") {
$dbh = DB::connect($content_connstring, 1);
} elseif ($type == "user") {
$dbh = DB::connect($user_connstring, 1);
}
if (DB::isError($dbh)) {
echo "<p><b>Database backend connection failed:</b>" .
$dbh->getMessage() . "</p>\n";
exit;
}
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
return($dbh);
}
Can anyone see what I'm doing wrong?
I don't assume that this is a PEAR-problem since it's two completely
different objects.. but I really can't figure out what's happening
here.. any help would be appreciated.
--
Trond Arve Nordheim
- "This message is ROT13-encrypted twice for extra security."