PHP code example of burn / yii2-db-archiver

1. Go to this page and download the library: Download burn/yii2-db-archiver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

burn / yii2-db-archiver example snippets


  /**
   * @throws \yii\base\InvalidConfigException
   */
  public function actionArchiveErrorsLog()
  {
      /** @var \burn\dbArchiver\DbArchiver $dbArchiver */
      $dbArchiver = \Yii::$app->get('dbArchiver');
      $dbArchiver
          ->getQuery()
          ->setArchivedModel(LogError::className())
          ->setDirect(true)
          ->setDateColumn('log_time')
          ->setMkTimeDateColumn(true);
      if (!$dbArchiver->actionArchive()) {
          \Yii::error(LogError::tableName() . ' table not archived!');
          echo 'Something went wrong! '. LogError::tableName() . ' table not archived!';
      }
  }

    /**
    * @throws \yii\base\InvalidConfigException
    */
    public function actionRestoreErrorsLog($filename)
    {
        /** @var \burn\dbArchiver\DbArchiver $dbArchiver */
        $dbArchiver = \Yii::$app->get('dbArchiver');
        $dbArchiver
            ->getQuery()
            ->setArchivedModel(LogError::className())
            ->setDirect(true);
        if (!$dbArchiver->actionRestoreFromFile($filename)) {
            \Yii::error(LogError::tableName() . ' table not restored!');
            echo 'Something went wrong! '. LogError::tableName() . ' table not restored!';
        }
    }