Example #1
0
 /**
  * {@inheritdoc}
  */
 public function add(IConnectionSingle $connection)
 {
     $parameters = $connection->getParameters();
     if (isset($parameters->alias)) {
         $this->_pool[$parameters->alias] = $connection;
     } else {
         $this->_pool[] = $connection;
     }
     $this->_distributor->add($connection, $parameters->weight);
 }
 /**
  * {@inheritdoc}
  */
 public function remove(IConnectionSingle $connection)
 {
     if ($connection->getParameters()->alias === 'master') {
         $this->master = null;
         $this->reset();
         return true;
     } else {
         if (($id = array_search($connection, $this->slaves, true)) !== false) {
             unset($this->slaves[$id]);
             $this->reset();
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function getParameters()
 {
     return $this->connection->getParameters();
 }
Example #4
0
 /**
  * Prepares a connection object after its initialization.
  *
  * @param IConnectionSingle $connection Instance of a connection object.
  * @param IServerProfile $profile $connection Instance of a connection object.
  */
 protected function prepareConnection(IConnectionSingle $connection, IServerProfile $profile)
 {
     $parameters = $connection->getParameters();
     if (isset($parameters->password)) {
         $command = $profile->createCommand('auth', array($parameters->password));
         $connection->pushInitCommand($command);
     }
     if (isset($parameters->database)) {
         $command = $profile->createCommand('select', array($parameters->database));
         $connection->pushInitCommand($command);
     }
 }