/** * Returns the currently active database connection. * By default, the 'db' application component will be returned and activated. * You can call {@link setDbConnection} to switch to a different database connection. * Methods such as {@link insert}, {@link createCollection} will use this database connection * to perform DB queries. * * @throws CException if "db" application component is not configured * @return EMongoClient the currently active mongodb connection */ public function getDbConnection() { if ($this->_db === null) { $this->_db = Yii::app()->getComponent('mongodb'); if (!$this->_db instanceof Client) { throw new Exception(Yii::t('yii', 'The "db" application component must be configured to be a mongoii\\Client object.')); } } return $this->_db->selectDatabase(); }
protected function getDbConnection() { if ($this->_db !== null) { return $this->_db; } elseif (($this->_db = Yii::app()->getComponent($this->connectionID)) instanceof Client) { return $this->_db->selectDatabase(); } echo "Error: mongoyii\\MigrateCommand.connectionID '{$this->connectionID}' is invalid. Please make sure it refers to the ID of a mongoyii\\Client application component.\n"; exit(1); }