Automatically switch to read-only database when the main database is not available
I am trying to find ways to switch between Master and Slave (Postgresql) database. If a Master is not available, SilverStripe will pick it up and switch the databases to the Slave (read-only) database.
I've read Sam Minnie 's post about this and I'm wondering if any work has been done on this? Ideally, this will be an automated action.
+3
source to share
1 answer
you can put code in your _config.php for example ...
global $databaseConfig;
$conn = new mysqli($databaseConfig['server'], $$databaseConfig['username'], $$databaseConfig['password']);
if ($conn->connect_error)
$otherDB = array(
"type" => 'MySQLDatabase',
"server" => 'localhost',
"username" => 'read_only_user',
"password" => 'some_password',
"path" => '',
"database" => 'other_database'
);
0
source to share