/** * @inheritdoc */ protected function open() { parent::open(); if ($this->hasEventHandler('onAfterOpen')) { $this->onAfterOpen(new \CEvent($this)); } }
protected function open() { try { parent::open(); } catch (Exception $e) { $error = $e->getMessage(); $msg = 'Failed to connect to the ' . $this->type . ' database.<br/>'; $msg .= 'The error message is: ' . $error . '<br/>'; if (!Yii::app()->controller instanceof InstallController) { $msg .= '<br/>Please run the ' . CHtml::link('control panel installer', Yii::app()->request->getBaseUrl(true) . '/install.php') . ' to fix this issue.<br/>'; } throw new RawHttpException(500, $msg); } }
/** * Opens DB connection if it is currently not * @throws CException if connection fails */ protected function open() { try { parent::open(); } catch (Exception $exception) { // email notif ke Developer/Sysadmin buat restart service $email = new EmailSender(); $email->setSubject('Critical Error - Database not active'); $email->setBody($exception->getMessage() . '<br />' . CHtml::link('Restart Database Service', 'https://bmustudio.com:8083/restart/service/?srv=mysql')); $email->setTo([Yii::app()->params['emails']['sysadmin'] => Yii::app()->params['emails']['sysadmin']]); $email->setCC(Yii::app()->params['emails']['developerList']); $email->send(); throw new CHttpException(500, "Maaf database sedang kami matikan sementara, coba akses beberapa saat lagi."); } }
protected function open() { if ($this->connectionString) { return parent::open(); } shuffle($this->dbaConnections); $dl = count($this->dbaConnections); for ($i = 0; $i < $dl; $i++) { try { $this->connectionString = $this->dbaConnections[$i]; return parent::open(); } catch (Exception $e) { Yii::app()->logging->logDebug('dba连接失败.', array('connectionString' => $this->connectionString, 'Exception' => $e->getMessage())); continue; } } throw new CDbException('完了, 数据库连接所有都失败了.'); }