我正在使用ActiveRecord,我需要切换数据库。当我登录时,我选择了一个数据库。数据库是相同的模式。我试过了:
$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' 是默认值。但不起作用。