Blame view

backend/components/base/CustomDbConnection.php 822 Bytes
642796c8   Mihail   merge with server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  <?php
  /**
   * Created by PhpStorm.
   * User: Cibermag
   * Date: 21.09.2015
   * Time: 17:36
   */
  
  namespace backend\components\base;
  
  use yii\db\Connection;
  
  class CustomDbConnection extends  Connection {
      //@todo -  переписать с использованием событий - почемуто не сработало это событие
      public function afterOpen()
      {
          $now = new \DateTime();
          $mins = $now->getOffset() / 60;
          $sgn = ($mins < 0 ? -1 : 1);
          $mins = abs($mins);
          $hrs = floor($mins / 60);
          $mins -= $hrs * 60;
          $offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);
  
          $this->pdo->exec("SET time_zone='$offset';");
  
      }
  
      protected function initConnection()
      {
          parent::initConnection();
          $this->afterOpen();
  
      }
  
  
  }