本文整理汇总了PHP中DatabaseCompatibilityUtil::createDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseCompatibilityUtil::createDatabase方法的具体用法?PHP DatabaseCompatibilityUtil::createDatabase怎么用?PHP DatabaseCompatibilityUtil::createDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseCompatibilityUtil
的用法示例。
在下文中一共展示了DatabaseCompatibilityUtil::createDatabase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDatabaseBackupAndRestore
public function testDatabaseBackupAndRestore()
{
// Create new database (zurmo_wacky).
if (RedBeanDatabase::getDatabaseType() == 'mysql') {
$this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->hostname, $this->rootUsername, $this->rootPassword, $this->databasePort, $this->temporaryDatabaseName));
$connection = @mysql_connect($this->hostname . ':' . $this->databasePort, $this->rootUsername, $this->rootPassword);
$this->assertTrue(is_resource($connection));
@mysql_select_db($this->temporaryDatabaseName);
@mysql_query("create table temptable (temptable_id int(11) unsigned not null)", $connection);
@mysql_query("insert into temptable values ('5')", $connection);
@mysql_query("insert into temptable values ('10')", $connection);
$result = @mysql_query("SELECT count(*) from temptable");
$totalRows = mysql_fetch_row($result);
@mysql_close($connection);
$this->assertEquals(2, $totalRows[0]);
$this->assertTrue(DatabaseCompatibilityUtil::backupDatabase('mysql', $this->hostname, $this->rootUsername, $this->rootPassword, $this->temporaryDatabaseName, $this->databaseBackupTestFile));
//Drop database, and restore it from backup.
$this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->hostname, $this->rootUsername, $this->rootPassword, $this->databasePort, $this->temporaryDatabaseName));
$this->assertTrue(DatabaseCompatibilityUtil::restoreDatabase('mysql', $this->hostname, $this->rootUsername, $this->rootPassword, $this->temporaryDatabaseName, $this->databaseBackupTestFile));
$connection = @mysql_connect($this->hostname . ':' . $this->databasePort, $this->rootUsername, $this->rootPassword);
$this->assertTrue(is_resource($connection));
@mysql_select_db($this->temporaryDatabaseName);
$result = @mysql_query("SELECT count(*) from temptable");
$totalRows = mysql_fetch_row($result);
$result = @mysql_query("SELECT * from temptable");
$rows1 = mysql_fetch_row($result);
$rows2 = mysql_fetch_row($result);
@mysql_close($connection);
$this->assertEquals(2, $totalRows[0]);
$this->assertEquals(5, $rows1[0]);
$this->assertEquals(10, $rows2[0]);
}
}
示例2: afterValidate
/**
* After the standard validation is completed, check the database connections.
* @see CModel::afterValidate()
*/
public function afterValidate()
{
parent::afterValidate();
if (count($this->getErrors()) == 0) {
//check memcache first, since creating the db / user should be last.
if ($this->memcacheHostname != null) {
if ($this->memcachePortNumber == null) {
$this->addError('memcachePortNumber', Zurmo::t('InstallModule', 'Since you specified a memcache ' . 'hostname, you must specify a port.'));
return;
}
$memcacheResult = InstallUtil::checkMemcacheConnection($this->memcacheHostname, (int) $this->memcachePortNumber);
if ($memcacheResult !== true) {
$this->addError('memcacheHostname', Zurmo::t('InstallModule', 'Error code:') . " " . $memcacheResult[0] . '<br/>Message(Memcached): ' . $memcacheResult[1]);
return;
}
}
if (!$this->hostInfo) {
$this->addError('hostInfo', Zurmo::t('InstallModule', 'Please enter server IP or URL.'));
return;
} else {
if (strpos($this->hostInfo, 'http://') === false && strpos($this->hostInfo, 'https://') === false) {
$this->addError('hostInfo', Zurmo::t('InstallModule', 'Host Info must start with "http://" or "https://".'));
return;
}
}
if ($this->databaseAdminUsername != null) {
if ($this->databaseAdminPassword == null) {
$this->addError('databaseAdminPassword', Zurmo::t('InstallModule', 'Since you specified a database ' . 'admin username, you must enter a password'));
return;
}
$connectionResult = DatabaseCompatibilityUtil::checkDatabaseConnection($this->databaseType, $this->databaseHostname, $this->databaseAdminUsername, $this->databaseAdminPassword, (int) $this->databasePort);
if ($connectionResult !== true) {
$this->addError('databaseAdminUsername', Zurmo::t('InstallModule', 'Error code:') . " " . $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
return;
}
$userExistsResult = DatabaseCompatibilityUtil::checkDatabaseUserExists($this->databaseType, $this->databaseHostname, $this->databaseAdminUsername, $this->databaseAdminPassword, (int) $this->databasePort, $this->databaseUsername);
if ($userExistsResult === true) {
$this->addError('databaseUsername', Zurmo::t('InstallModule', 'You have specified an existing user. ' . 'If you would like to use this user, then do not specify the database admin username and ' . 'password. Otherwise pick a database username that does not exist.'));
return;
}
$databaseExistsResult = DatabaseCompatibilityUtil::checkDatabaseExists($this->databaseType, $this->databaseHostname, $this->databaseAdminUsername, $this->databaseAdminPassword, (int) $this->databasePort, $this->databaseName);
if ($databaseExistsResult === true) {
$this->addError('databaseName', Zurmo::t('InstallModule', 'You have specified an existing database. ' . 'If you would like to use this database, then do not specify the database admin username and ' . 'password. Otherwise pick a database name that does not exist.'));
return;
}
$createDatabaseResult = DatabaseCompatibilityUtil::createDatabase($this->databaseType, $this->databaseHostname, $this->databaseAdminUsername, $this->databaseAdminPassword, (int) $this->databasePort, $this->databaseName);
if ($createDatabaseResult === false) {
$this->addError('databaseName', Zurmo::t('InstallModule', 'There was a problem creating the database ' . 'Error code:') . " " . $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
return;
}
$createUserResult = DatabaseCompatibilityUtil::createDatabaseUser($this->databaseType, $this->databaseHostname, $this->databaseAdminUsername, $this->databaseAdminPassword, (int) $this->databasePort, $this->databaseName, $this->databaseUsername, $this->databasePassword);
if ($createUserResult === false) {
$this->addError('databaseUsername', Zurmo::t('InstallModule', 'There was a problem creating the user ' . 'Error code:') . " " . $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
return;
}
} else {
$connectionResult = DatabaseCompatibilityUtil::checkDatabaseConnection($this->databaseType, $this->databaseHostname, $this->databaseUsername, $this->databasePassword, (int) $this->databasePort);
if ($connectionResult !== true) {
$this->addError('databaseUsername', Zurmo::t('InstallModule', 'Error code:') . " " . $connectionResult[0] . '<br/>Message: ' . $connectionResult[1]);
return;
}
$databaseExistsResult = DatabaseCompatibilityUtil::checkDatabaseExists($this->databaseType, $this->databaseHostname, $this->databaseUsername, $this->databasePassword, (int) $this->databasePort, $this->databaseName);
if ($databaseExistsResult !== true) {
$this->addError('databaseName', Zurmo::t('InstallModule', 'The database name specified does not ' . 'exist or the user specified does not have access.') . '<br/>' . Zurmo::t('InstallModule', 'Error code:') . " " . $databaseExistsResult[0] . '<br/>Message: ' . $databaseExistsResult[1]);
return;
} else {
if ($this->removeExistingData == false) {
$this->addError('removeExistingData', Zurmo::t('InstallModule', 'Since you specified an existing database ' . 'you must check this box in order to proceed. THIS WILL REMOVE ALL EXISTING DATA.'));
return;
}
}
}
}
}
示例3: testBackupAndRestoreDatabase
public function testBackupAndRestoreDatabase()
{
chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
// Create new database (zurmo_temp).
if (RedBeanDatabase::getDatabaseType() == 'mysql') {
$this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->temporaryDatabaseHostname, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort, $this->temporaryDatabaseName));
$connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword);
$this->assertTrue(is_resource($connection));
@mysql_select_db($this->temporaryDatabaseName);
@mysql_query("create table temptable (temptable_id int(11) unsigned not null)", $connection);
@mysql_query("insert into temptable values ('5')", $connection);
@mysql_query("insert into temptable values ('10')", $connection);
$result = @mysql_query("SELECT count(*) from temptable");
$totalRows = mysql_fetch_row($result);
@mysql_close($connection);
$this->assertEquals(2, $totalRows[0]);
$command = "php zurmocTest.php database backup {$this->databaseBackupTestFile} mysql ";
$command .= "{$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
$command .= "{$this->temporaryDatabasePort} {$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword}";
if (!IS_WINNT) {
$command .= ' 2>&1';
}
exec($command, $output);
sleep(2);
$this->assertTrue(is_file($this->databaseBackupTestFile));
//Drop database, and restore it from backup.
$this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->temporaryDatabaseHostname, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort, $this->temporaryDatabaseName));
// Ensure that database don't exist
$connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword);
$this->assertTrue(is_resource($connection));
@mysql_select_db($this->temporaryDatabaseName, $connection);
$result = @mysql_query("SELECT count(*) from temptable", $connection);
$this->assertFalse($result);
// Now restore database
$command = "php zurmocTest.php database restore {$this->databaseBackupTestFile} mysql ";
$command .= "{$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} ";
$command .= "{$this->temporaryDatabasePort} {$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword}";
if (!IS_WINNT) {
$command .= ' 2>&1';
}
exec($command, $output);
sleep(2);
$connection = @mysql_connect($this->temporaryDatabaseHostname . ':' . $this->temporaryDatabasePort, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword);
$this->assertTrue(is_resource($connection));
$result = @mysql_select_db($this->temporaryDatabaseName, $connection);
$this->assertTrue($result);
$result = @mysql_query("SELECT count(*) from temptable", $connection);
$this->assertTrue(is_resource($result));
$totalRows = mysql_fetch_row($result);
$result = @mysql_query("SELECT * from temptable", $connection);
$rows1 = mysql_fetch_row($result);
$rows2 = mysql_fetch_row($result);
@mysql_close($connection);
$this->assertEquals(2, $totalRows[0]);
$this->assertEquals(5, $rows1[0]);
$this->assertEquals(10, $rows2[0]);
}
}
示例4: testConnectToDatabaseCreateSuperUserBuildDatabaseAndFreeze
public function testConnectToDatabaseCreateSuperUserBuildDatabaseAndFreeze()
{
// This test cannot run as saltdev. It is therefore skipped on the server.
if ($this->temporaryDatabaseUsername == 'root') {
$this->assertTrue(DatabaseCompatibilityUtil::createDatabase('mysql', $this->temporaryDatabaseHostname, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort, $this->temporaryDatabaseName));
$this->assertTrue(DatabaseCompatibilityUtil::createDatabaseUser('mysql', $this->temporaryDatabaseHostname, $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort, $this->temporaryDatabaseName, 'wacko', 'wacked'));
InstallUtil::connectToDatabase('mysql', $this->temporaryDatabaseHostname, 'wacky', $this->temporaryDatabaseUsername, $this->temporaryDatabasePassword, $this->temporaryDatabasePort);
Yii::app()->user->userModel = InstallUtil::createSuperUser('super', 'super');
$messageLogger = new MessageLogger();
InstallUtil::autoBuildDatabase($messageLogger);
$this->assertFalse($messageLogger->isErrorMessagePresent());
ReadPermissionsOptimizationUtil::rebuild();
InstallUtil::freezeDatabase();
$tableNames = R::getCol('show tables');
$this->assertEquals(array('_group', '_group__user', '_right', '_user', 'account', 'account_read', 'activity', 'activity_item', 'actual_permissions_cache', 'address', 'auditevent', 'contact', 'contact_opportunity', 'contact_read', 'contactstate', 'currency', 'currencyvalue', 'customfield', 'customfielddata', 'dashboard', 'email', 'filecontent', 'filemodel', 'globalmetadata', 'item', 'log', 'mashableactivity', 'meeting', 'meeting_read', 'namedsecurableitem', 'note', 'note_read', 'opportunity', 'opportunity_read', 'ownedcustomfield', 'ownedsecurableitem', 'permission', 'permitable', 'person', 'perusermetadata', 'policy', 'portlet', 'role', 'securableitem', 'task', 'task_read'), $tableNames);
}
}