本文整理汇总了PHP中CDbConnection::getServerVersion方法的典型用法代码示例。如果您正苦于以下问题:PHP CDbConnection::getServerVersion方法的具体用法?PHP CDbConnection::getServerVersion怎么用?PHP CDbConnection::getServerVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDbConnection
的用法示例。
在下文中一共展示了CDbConnection::getServerVersion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($sArgument)
{
if (!isset($sArgument) || !isset($sArgument[0]) || !isset($sArgument[1]) || !isset($sArgument[2]) || !isset($sArgument[3])) {
die('You have to set admin/password/full name and email address on the command line like this: php starter.php adminname mypassword fullname emailaddress');
}
Yii::import('application.helpers.common_helper', true);
try {
$this->connection = App()->getDb();
$this->connection->active = true;
} catch (CDbException $e) {
$this->createDatabase();
}
$this->connection->charset = 'utf8';
switch ($this->connection->driverName) {
case 'mysql':
case 'mysqli':
$this->connection->createCommand("ALTER DATABASE " . $this->connection->quoteTableName($this->getDBConnectionStringProperty('dbname')) . " DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")->execute();
$sql_file = 'mysql';
break;
case 'pgsql':
if (version_compare($this->connection->getServerVersion(), '9', '>=')) {
$this->connection->createCommand("ALTER DATABASE " . $this->connection->quoteTableName($this->getDBConnectionStringProperty('dbname')) . " SET bytea_output='escape';")->execute();
}
$sql_file = 'pgsql';
break;
case 'dblib':
case 'mssql':
case 'sqlsrv':
$sql_file = 'mssql';
break;
default:
throw new Exception(sprintf('Unknown database type "%s".', $this->connection->driverName));
}
$this->_executeSQLFile(dirname(Yii::app()->basePath) . '/installer/sql/create-' . $sql_file . '.sql');
$this->connection->createCommand()->insert($this->connection->tablePrefix . 'users', array('users_name' => $sArgument[0], 'password' => hash('sha256', $sArgument[1]), 'full_name' => $sArgument[2], 'parent_id' => 0, 'lang' => 'auto', 'email' => $sArgument[3]));
$this->connection->createCommand()->insert($this->connection->tablePrefix . 'permissions', array('entity' => 'global', 'entity_id' => 0, 'uid' => 1, 'permission' => 'superadmin', 'create_p' => 0, 'read_p' => 1, 'update_p' => 0, 'delete_p' => 0, 'import_p' => 0, 'export_p' => 0));
}
示例2: array
/**
* Installer::_setup_tables()
* Function that actually modify the database. Read $sqlfile and execute it.
* @param string $sqlfile
* @return Empty string if everything was okay - otherwise the error messages
*/
function _setup_tables($sFileName, $aDbConfig = array(), $sDatabasePrefix = '')
{
extract(empty($aDbConfig) ? self::_getDatabaseConfig() : $aDbConfig);
switch ($sDatabaseType) {
case 'mysql':
case 'mysqli':
$this->connection->createCommand("ALTER DATABASE " . $this->connection->quoteTableName($sDatabaseName) . " DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")->execute();
break;
case 'pgsql':
if (version_compare($this->connection->getServerVersion(), '9', '>=')) {
$this->connection->createCommand("ALTER DATABASE " . $this->connection->quoteTableName($sDatabaseName) . " SET bytea_output='escape';")->execute();
}
break;
}
return $this->_executeSQLFile($sFileName, $sDatabasePrefix);
}
示例3: stepDatabaseConfiguration
/**
* Configure database screen
*/
private function stepDatabaseConfiguration()
{
$this->loadHelper('surveytranslator');
$aData['clang'] = $clang = $this->lang;
// usual data required by view
$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;
$aData['model'] = $oModel = new InstallerConfigForm();
if (isset(Yii::app()->session['populateerror'])) {
$oModel->addError('dblocation', Yii::app()->session['populateerror']);
$oModel->addError('dbpwd', '');
$oModel->addError('dbuser', '');
unset(Yii::app()->session['populateerror']);
}
if (isset($_POST['InstallerConfigForm'])) {
$oModel->attributes = $_POST['InstallerConfigForm'];
//run validation, if it fails, load the view again else proceed to next step.
if ($oModel->validate()) {
$sDatabaseType = $oModel->dbtype;
$sDatabaseName = $oModel->dbname;
$sDatabaseUser = $oModel->dbuser;
$sDatabasePwd = $oModel->dbpwd;
$sDatabasePrefix = $oModel->dbprefix;
$sDatabaseLocation = $oModel->dblocation;
$sDatabasePort = '';
if (strpos($sDatabaseLocation, ':') !== false) {
list($sDatabaseLocation, $sDatabasePort) = explode(':', $sDatabaseLocation, 2);
} else {
$sDatabasePort = self::_getDbPort($sDatabaseType, $sDatabasePort);
}
$bDBExists = false;
$bDBConnectionWorks = false;
$aDbConfig = compact('sDatabaseType', 'sDatabaseName', 'sDatabaseUser', 'sDatabasePwd', 'sDatabasePrefix', 'sDatabaseLocation', 'sDatabasePort');
if (self::_dbConnect($aDbConfig, array())) {
$bDBExists = true;
$bDBConnectionWorks = true;
} else {
$aDbConfig['sDatabaseName'] = '';
if (self::_dbConnect($aDbConfig, array())) {
$bDBConnectionWorks = true;
} else {
$oModel->addError('dblocation', $clang->gT('Connection with database failed. Please check database location, user name and password and try again.'));
$oModel->addError('dbpwd', '');
$oModel->addError('dbuser', '');
}
}
//if connection with database fail
if ($bDBConnectionWorks) {
//saving the form data
foreach (array('dbname', 'dbtype', 'dbpwd', 'dbuser', 'dbprefix') as $sStatusKey) {
Yii::app()->session[$sStatusKey] = $oModel->{$sStatusKey};
}
Yii::app()->session['dbport'] = $sDatabasePort;
Yii::app()->session['dblocation'] = $sDatabaseLocation;
//check if table exists or not
$bTablesDoNotExist = false;
// Check if the surveys table exists or not
if ($bDBExists == true) {
try {
if ($dataReader = $this->connection->createCommand()->select()->from('{{users}}')->query()->rowCount == 0) {
// DBLIB does not throw an exception on a missing table
$bTablesDoNotExist = true;
}
} catch (Exception $e) {
$bTablesDoNotExist = true;
}
}
$bDBExistsButEmpty = $bDBExists && $bTablesDoNotExist;
//store them in session
Yii::app()->session['databaseexist'] = $bDBExists;
Yii::app()->session['tablesexist'] = !$bTablesDoNotExist;
// If database is up to date, redirect to administration screen.
if ($bDBExists && !$bTablesDoNotExist) {
Yii::app()->session['optconfig_message'] = sprintf('<b>%s</b>', $clang->gT('The database you specified does already exist.'));
Yii::app()->session['step3'] = true;
//wrte config file! as we no longer redirect to optional view
$this->_writeConfigFile();
//$this->redirect(array("installer/loadOptView"));
header("refresh:5;url=" . $this->createUrl("/admin"));
echo sprintf($clang->gT('The database does exists and contains LimeSurvey tables. You\'ll be redirected to the database update or (if your database is already up to date) to the administration login in 5 seconds. If not, please click <a href="%s">here</a>.', 'unescaped'), $this->createUrl("/admin"));
exit;
}
if (in_array($oModel->dbtype, array('mysql', 'mysqli'))) {
//for development - use mysql in the strictest mode //Checked)
if (Yii::app()->getConfig('debug') > 1) {
$this->connection->createCommand("SET SESSION SQL_MODE='STRICT_ALL_TABLES,ANSI'")->execute();
}
$sMySQLVersion = $this->connection->getServerVersion();
if (version_compare($sMySQLVersion, '4.1', '<')) {
die("<br />Error: You need at least MySQL version 4.1 to run LimeSurvey. Your version:" . $sMySQLVersion);
}
@$this->connection->createCommand("SET CHARACTER SET 'utf8'")->execute();
//Checked
@$this->connection->createCommand("SET NAMES 'utf8'")->execute();
//Checked
//.........这里部分代码省略.........