RE: [PEAR] Multiple Pear DB-connections

From: Date: Tue, 14 May 2002 15:18:13 +0000
Subject: RE: [PEAR] Multiple Pear DB-connections
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1371@lists.php.net to get a copy of this message
my guess would be that DB::connect is a factory-like object that returns a singleton, i.e. each time it is called it returns a reference to the same object of course, I did not look at the code, but it seems to be the case. -anton -----Original Message----- From: Trond Arve Nordheim [mailto:trond@nordheim.no] Sent: Tuesday, May 14, 2002 11:15 AM To: pear-general@lists.php.net Subject: [PEAR] Multiple Pear DB-connections 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." -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.general (#1371) next »