Re: DB singleton function?

From: Date: Tue, 26 Oct 2004 21:26:23 +0000
Subject: Re: DB singleton function?
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34087@lists.php.net to get a copy of this message
Ian Eure wrote:
On Tuesday 26 October 2004 02:02 pm, Joe Stump wrote:
Why isn't there a DB singleton function like there is in Log? It would be extremely simple to implement and could be used when PHP5 finally becomes standard. Ie. function &singleton ($dsn) {
     if (!isset($GLOBALS['_DB_Connections'][$dsn])) {
         $GLOBALS['_DB_Connections'][$dsn] = & DB::connect($dsn);
     }
     return $GLOBALS['_DB_Connections'][$dsn];
}
I was wondering this a while back, and I was going to work something up. I wasn't sure if singleton() should try to connect(), or just call factory(). Connecting seems like the right thing, but I think there's an assumption that singleton() will work like factory(), e.g. not connect. And connectSingleton() seemed like a pretty bad function name. Any DB developers have feedback on this issue?
Have a look at MDB2. You probably want a singleton per DSN. regards, Lukas

« previous php.pear.dev (#34087) next »