Facebook
From gryg, 5 Days ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 36
  1. <?php
  2. namespace App\Core;
  3.  
  4. use Illuminate\Database\Capsule\Manager;
  5.  
  6. /**
  7.  * DB manager class
  8.  */
  9. class DB extends Manager
  10. {
  11.     /**
  12.      * Dataset db prefix
  13.      * @var string
  14.      */
  15.     protected $datasetDatabasePrefix;
  16.  
  17.     /**
  18.      * Switch dataset
  19.      * @param  integer $datasetId
  20.      */
  21.     public static function switchDataset($datasetId)
  22.     {  
  23.         static::$instance->switchDatabaseName('dataset', $datasetId);
  24.     }
  25.  
  26.     /**
  27.      * Switch database name for given connection
  28.      * @param string $connection
  29.      * @param string $datasetId
  30.      */
  31.     public function switchDatabaseName($connection, $datasetId)
  32.     {
  33.         $config = $this->container['config']['database.connections'][$connection];
  34.         $config['database'] = $this->datasetDatabasePrefix.$datasetId;
  35.  
  36.         $this->addConnection($config, $connection);
  37.     }
  38.  
  39.     /**
  40.      * Set dataset database prefix
  41.      * @param string $prefix
  42.      * @return $this
  43.      */
  44.     public function setDatasetDatabasePrefix($prefix)
  45.     {
  46.         $this->datasetDatabasePrefix = $prefix;
  47.  
  48.         return $this;
  49.     }
  50. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Rude Matamata php 3 Days ago.