Created
June 27, 2019 00:50
-
-
Save muskie9/205e6dbbcb79d69734aa1b0b3c5087bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Your\Namespace; | |
use SilverStripe\Core\Config\Configurable; | |
use SilverStripe\ORM\DB; | |
/** | |
* Class ConnectionManager | |
* @package Your\Namespace | |
*/ | |
class ConnectionManager | |
{ | |
use Configurable; | |
/** | |
* @var array | |
*/ | |
private static $alternate = [ | |
'type' => 'MySQLDatabase', | |
'server' => 'localhost', | |
'username' => 'username', | |
'password' => 'password', | |
'database' => 'database', | |
]; | |
/** | |
* | |
*/ | |
public static function connect_default() | |
{ | |
DB::connect(DB::getConfig('default')); | |
} | |
/** | |
* | |
*/ | |
public static function connect_alternate() | |
{ | |
if (!DB::getConfig('alternate')) { | |
DB::setConfig(static::config()->get('alternate'), 'alternate'); | |
} | |
DB::connect(DB::getConfig('alternate')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Case