RE: [PHP-PEAR] PEAR Status
| From: | Chuck Hagenbuch | Date: | Mon, 26 Jun 2000 17:22:21 +0000 |
| Subject: | RE: [PHP-PEAR] PEAR Status | ||
| References: | 1 | Groups: | php.pear |
| Request: | Send a blank email to php-pear+get-126@lists.php.net to get a copy of this message | ||
Quoting Seth Fitzsimmons <seth@egrad2000.com>:
> In any case, it all seems to work, so thanks for your help! ($db = new
> DB_mysql;$db->connect("mysql:...");)
Glad to hear that. :)
> In a partially related question, does anyone know how it would be possible
> to share a single database connection (class) among a number of other
> classes without having to pass it as a parameter? (I think Java has
> something along this line - a connection pool or something).
You might be able to do something along these lines:
class Bar {
// {{{ singleton()
/**
* <b>You MUST call this method with the $var = &Bar::singleton()
* syntax. Without the ampersand (&) in front of the method name,
* you will not get a reference, you will get a copy.</b>
*/
function &singleton ($key) {
static $instances;
if (!isset($instances)) $instances = array();
$signature = md5($key);
if (!isset($instances[$signature])) {
$instances[$signature] = new Bar();
}
return $instances[$signature];
}
// }}}
}
I wrote that to provide a way to create only one copy of a class instance. You
could probably modify it pretty easily to have a pool of them...
-chuck
--
I won't die for Fernando Poo