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 参数(它已经被指定为参数!!)但就我现在所见而言还不够。