Registration mode:
1 classdbconnections{2 var $_store=Array();3 Public functionIsValid ($key) {4 return isset($this->_store[$key]);5 }6 7 Public function&get ($key){8 if(isset($this->_store[$key])) 9 return $this->_store[$key];Ten } One A Public functionSet$key, &$obj) { - $this->_store[$key] = &$obj; - } the - Public function&getinstance () { - Static $instance=Array(); - if(!$instance) + $instance[0] = &Newdbconnections; - return $instance[0]; + } A } at - classmysqlconnection{ - Public $name=false; - Public function__construct ($db){ - $this->name =$db; - Echo $db, "\ n"; in } - to Public functionAppend$str){ + $this->name. = "".$str; - } the } * $ //initial setup, somewhere near the start of your scriptPanax Notoginseng $dbc= & Dbconnections::getinstance (); - $dbc->set (' Server1 ',NewMysqlconnection (' DB1 ')); the $dbc->set (' Server2 ',NewMysqlconnection (' DB2 ')); + $dbc->set (' Server3 ',NewMysqlconnection (' db3 ')); A the + $DBC 1=$dbc->get (' Server1 '); - $DBC 2=$dbc->get (' Server2 '); $ $DBC 3=$dbc->get (' Server3 '); $ - $DBC 1->append ("Connection"); - the Var_dump($dbc->get (' Server1 ')); - Var_dump($dbc->get (' Server2 '));Wuyi Var_dump($dbc->get (' Server3 '));
Review PHP design mode--Registration mode