Re: DB singleton function?
| From: | Hans Lellelid | Date: | Thu, 28 Oct 2004 02:40:22 +0000 |
| Subject: | Re: DB singleton function? | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34112@lists.php.net to get a copy of this message | ||
Hi Ian -
Yeah... I know how singletons work, I'm just not sure if it should connect to the DB or just create the instance.One thing related to this topic .... some APIs like mysql (is mysql the only one?) will re-use existing connections if you pass in the same connection parameters. WI'd suggest that this behavior be avoided (by passing a force-new-connection arg to mysql_[p]connect() method) and that a singleton be implemented instead. Perhaps the [M]DB libs already do this, but the reason why [M]DB does a mysql_select_db() before every query is precisely this: that you cannot otherwise use two databases on the same server, since the _same_ db link id would have been returned for both connections. Yeah, anyway, I think the singleton() addition is a good idea; it's good it exists in MDB2. Personally, I think that the name singleton() is pretty jargon-esque, and that getInstance() might be clearer, but that's just my opinion. I think technically the singleton implemented by MDB (or see almost any of the core Horde classes for similar implementations) is not a "singleton" at all since there is more than one instance (i.e. one instance per DSN), and by definition singleton = 1 instance. Cheers, Hans