Ich hab hier mal ganz grob eine Loesungemoeglichkeit entworfen:
PHP-Code:
$GLOBALS['__datenbank_config'] = array();
class datenbank {
function datenbank($id = 0) {
$conf =& $GLOBALS['__datenbank_config'][$id];
list($this->host, $this->user, $this->pass, $this->db) = $conf;
// connect etc.
}
function &getInstance($id = 0) {
static $instance = array();
if (is_null($instance[$id])) {
$instance[$id] =& new datenbank($id);
}
return $instance;
}
function setConfig($host, $user, $pass, $db, $id = 0) {
$conf =& $GLOBALS['__datenbank_config'];
$conf[$id] = array($host, $user, $pass, $db);
}
}
//Das ganze koennte man dan so verwenden:
Datenbank::setConfig('localhost', 'test', '', 'test');
Class foo {
function foo() {
$this->db =& Datenbank::getInstance();
// $this->db->query() etc...
}
}
Wie gesagt man koennte es auch anders Loesen. Fehlerueberpruefung fehlt (gibt es diese ID?). Den unschoenen Weg ueber global kann man sich mit der ZE2 und statischen Klassenvariablen sparen.
HTH Andre