I'm using ActiveRecord and I need switching databases. When I log-in I select a database. The databases are the same schema. I tried:
$connections = array(
'1' => 'mysql://root:pass@localhost/db1;charset=utf8',
'2' => 'mysql://root:pass@localhost/db2;charset=utf8',
'test' => 'mysql://root:password@localhost/database_name'
);
$current_db = $_SESSION['db'] ? $_SESSION['db'] : '2';
ActiveRecord\Config::initialize(function($cfg) use ($connections, $current_db)
{
$cfg->set_model_directory(MODEL_PATH);
$cfg->set_connections($connections);
$cfg->set_default_connection($current_db);
});
db '2' is default. But does not work.