當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DatabaseCompatibilityUtil::backupDatabase方法代碼示例

本文整理匯總了PHP中DatabaseCompatibilityUtil::backupDatabase方法的典型用法代碼示例。如果您正苦於以下問題:PHP DatabaseCompatibilityUtil::backupDatabase方法的具體用法?PHP DatabaseCompatibilityUtil::backupDatabase怎麽用?PHP DatabaseCompatibilityUtil::backupDatabase使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DatabaseCompatibilityUtil的用法示例。


在下文中一共展示了DatabaseCompatibilityUtil::backupDatabase方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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]);
     }
 }
開發者ID:youprofit,項目名稱:Zurmo,代碼行數:33,代碼來源:DatabaseCompatibilityUtilTest.php

示例2: backupDatabase

 /**
  * Backup database
  * @param string $filePath
  * @param MessageStreamer $messageStreamer
  * @param $databaseType
  * @param $databaseHost
  * @param $databaseName
  * @param $databasePort
  * @param $databaseUsername
  * @param $databasePassword
  */
 protected function backupDatabase($filePath, $messageStreamer, $databaseType, $databaseHost, $databaseName, $databasePort, $databaseUsername, $databasePassword)
 {
     // If file already exist, ask user to confirm that want to overwrite it.
     if (file_exists($filePath)) {
         $message = Zurmo::t('Commands', 'Backup file already exists. Are you sure you want to overwrite the existing file?.');
         if (!$this->confirm($message)) {
             $messageStreamer->add(Zurmo::t('Commands', 'Backup not completed.'));
             $messageStreamer->add(Zurmo::t('Commands', 'Please delete existing file or enter new one, and start backup process again.'));
             Yii::app()->end();
         }
     }
     $messageStreamer->add(Zurmo::t('Commands', 'Starting database backup process.'));
     $result = DatabaseCompatibilityUtil::backupDatabase($databaseType, $databaseHost, $databaseUsername, $databasePassword, $databasePort, $databaseName, $filePath);
     if ($result) {
         $messageStreamer->add(Zurmo::t('Commands', 'Database backup completed.'));
     } else {
         $messageStreamer->add(Zurmo::t('Commands', 'There was an error during backup.'));
         // It is possible that empty file is created, so delete it.
         if (file_exists($filePath)) {
             $messageStreamer->add(Zurmo::t('Commands', 'Deleting backup file.'));
             unlink($filePath);
         }
         $messageStreamer->add(Zurmo::t('Commands', 'Please backup database manually.'));
     }
 }
開發者ID:youprofit,項目名稱:Zurmo,代碼行數:36,代碼來源:DatabaseCommand.php


注:本文中的DatabaseCompatibilityUtil::backupDatabase方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。