本文整理汇总了PHP中CDbConnection::getActive方法的典型用法代码示例。如果您正苦于以下问题:PHP CDbConnection::getActive方法的具体用法?PHP CDbConnection::getActive怎么用?PHP CDbConnection::getActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDbConnection
的用法示例。
在下文中一共展示了CDbConnection::getActive方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stepOptionalConfiguration
/**
* Optional settings screen
*/
private function stepOptionalConfiguration()
{
$aData['clang'] = $clang = $this->lang;
$aData['confirmation'] = Yii::app()->session['optconfig_message'];
$aData['title'] = $clang->gT("Optional settings");
$aData['descp'] = $clang->gT("Optional settings to give you a head start");
$aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'on');
$aData['progressValue'] = 80;
$this->loadHelper('surveytranslator');
$aData['model'] = $model = new InstallerConfigForm('optional');
if (isset($_POST['InstallerConfigForm'])) {
$model->attributes = $_POST['InstallerConfigForm'];
//run validation, if it fails, load the view again else proceed to next step.
if ($model->validate()) {
$sDefaultAdminUserName = $model->adminLoginName;
$sDefaultAdminPassword = $model->adminLoginPwd;
$sDefaultAdminRealName = $model->adminName;
$sDefaultSiteName = $model->siteName;
$sDefaultSiteLanguage = $model->surveylang;
$sDefaultAdminEmail = $model->adminEmail;
$aData['title'] = $clang->gT("Database configuration");
$aData['descp'] = $clang->gT("Please enter the database settings you want to use for LimeSurvey:");
$aData['classesForStep'] = array('off', 'off', 'off', 'on', 'off', 'off');
$aData['progressValue'] = 40;
//config file is written, and we've a db in place
$this->connection = Yii::app()->db;
//checking DB Connection
if ($this->connection->getActive() == true) {
$sPasswordHash = hash('sha256', $sDefaultAdminPassword);
try {
if (User::model()->count() > 0) {
die;
}
// Save user
$user = new User();
// Fix UserID to 1 for MySQL even if installed in master-master configuration scenario
if (in_array($this->connection->getDriverName(), array('mysql', 'mysqli'))) {
$user->uid = 1;
}
$user->users_name = $sDefaultAdminUserName;
$user->password = $sPasswordHash;
$user->full_name = $sDefaultAdminRealName;
$user->parent_id = 0;
$user->lang = $sDefaultSiteLanguage;
$user->email = $sDefaultAdminEmail;
$user->save();
// Save permissions
$permission = new Permission();
$permission->entity_id = 0;
$permission->entity = 'global';
$permission->uid = $user->uid;
$permission->permission = 'superadmin';
$permission->read_p = 1;
$permission->save();
// Save global settings
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'SessionName', 'stg_value' => self::_getRandomString()));
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'sitename', 'stg_value' => $sDefaultSiteName));
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminname', 'stg_value' => $sDefaultAdminRealName));
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminemail', 'stg_value' => $sDefaultAdminEmail));
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'siteadminbounce', 'stg_value' => $sDefaultAdminEmail));
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'defaultlang', 'stg_value' => $sDefaultSiteLanguage));
// only continue if we're error free otherwise setup is broken.
} catch (Exception $e) {
throw new Exception(sprintf('Could not add optional settings: %s.', $e));
}
Yii::app()->session['deletedirectories'] = true;
$aData['title'] = $clang->gT("Success!");
$aData['descp'] = $clang->gT("LimeSurvey has been installed successfully.");
$aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'off');
$aData['progressValue'] = 100;
$aData['user'] = $sDefaultAdminUserName;
$aData['pwd'] = $sDefaultAdminPassword;
$this->render('/installer/success_view', $aData);
return;
}
} else {
// if passwords don't match, redirect to proper link.
Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', $clang->gT("Passwords don't match."));
$this->redirect(array('installer/optional'));
}
} elseif (empty(Yii::app()->session['configFileWritten'])) {
$this->_writeConfigFile();
}
$this->render('/installer/optconfig_view', $aData);
}
示例2: stepOptionalConfiguration
/**
* Optional settings screen
*/
private function stepOptionalConfiguration()
{
$aData['clang'] = $clang = $this->lang;
$aData['confirmation'] = Yii::app()->session['optconfig_message'];
$aData['title'] = $clang->gT("Optional settings");
$aData['descp'] = $clang->gT("Optional settings to give you a head start");
$aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'on');
$aData['progressValue'] = 80;
$this->loadHelper('surveytranslator');
$aData['model'] = $model = new InstallerConfigForm('optional');
if (isset($_POST['InstallerConfigForm'])) {
$model->attributes = $_POST['InstallerConfigForm'];
//run validation, if it fails, load the view again else proceed to next step.
if ($model->validate()) {
$adminLoginPwd = $model->adminLoginPwd;
$confirmPwd = $model->confirmPwd;
$defaultuser = $model->adminLoginName;
$defaultpass = $model->adminLoginPwd;
$siteadminname = $model->adminName;
$siteadminbounce = $siteadminemail = $model->adminEmail;
$sitename = $model->siteName;
$defaultlang = $model->surveylang;
$aData['title'] = $clang->gT("Database configuration");
$aData['descp'] = $clang->gT("Please enter the database settings you want to use for LimeSurvey:");
$aData['classesForStep'] = array('off', 'off', 'off', 'on', 'off', 'off');
$aData['progressValue'] = 40;
//config file is written, and we've a db in place
$this->connection = Yii::app()->db;
//checking DB Connection
if ($this->connection->getActive() == true) {
$password_hash = hash('sha256', $defaultpass);
try {
$this->connection->createCommand()->insert('{{users}}', array('users_name' => $defaultuser, 'password' => $password_hash, 'full_name' => $siteadminname, 'parent_id' => 0, 'lang' => $defaultlang, 'email' => $siteadminemail, 'create_survey' => 1, 'create_user' => 1, 'participant_panel' => 1, 'delete_user' => 1, 'superadmin' => 1, 'configurator' => 1, 'manage_template' => 1, 'manage_label' => 1));
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'SessionName', 'stg_value' => self::_getRandomString()));
foreach (array('sitename', 'siteadminname', 'siteadminemail', 'siteadminbounce', 'defaultlang') as $insert) {
$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => $insert, 'stg_value' => ${$insert}));
}
// only continue if we're error free otherwise setup is broken.
} catch (Exception $e) {
throw new Exception(sprintf('Could not add optional settings: %s.', $e));
}
Yii::app()->session['deletedirectories'] = true;
$aData['title'] = $clang->gT("Success!");
$aData['descp'] = $clang->gT("LimeSurvey has been installed successfully.");
$aData['classesForStep'] = array('off', 'off', 'off', 'off', 'off', 'off');
$aData['progressValue'] = 100;
$aData['user'] = $defaultuser;
$aData['pwd'] = $defaultpass;
$this->render('/installer/success_view', $aData);
exit;
}
} else {
// if passwords don't match, redirect to proper link.
Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', $clang->gT("Passwords don't match."));
$this->redirect($this->createUrl('installer/optional'));
}
} elseif (empty(Yii::app()->session['configFileWritten'])) {
$this->_writeConfigFile();
}
$this->render('/installer/optconfig_view', $aData);
}
示例3: getIsConnected
public function getIsConnected()
{
return $this->db && $this->db->getActive();
}