getConnection 的定义引用了与上面使用的不同的参数顺序。
function getConnection($target = 'default', $key = NULL)
可悲的是,这与 Database::addConnectionInfo() 不同,后者是
public static function addConnectionInfo($key, $target, $info)
此外,在 DB_select 上,$key 不是参数,尽管它位于选项数组中:
function db_select($table, $alias = NULL, array $options = array()) {
if (empty($options['target'])) {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->select($table, $alias, $options);
}
尽管
final public static function getConnection($target = 'default', $key = NULL) {
所以这意味着'master'或'slave'或'default'总是作为设置使用,但不是替代数据库/模式的关键,需要 db_set_active('...'); 和 db_set_active(); db_select 周围。
由于在 db_select 的处理过程中很容易需要调用其他 dbs(例如 devel 调用或 alters 中的调用),因此这是一种不灵活的设计。更改此调用:
return Database::getConnection($options['target'])->select($table, $alias, $options);
需要添加 Key 参数(它已经被指定为参数!!),但就我现在所见而言还不够。