为的getConnection的定义列举了参数比上面使用不同的顺序。
function getConnection($target = 'default', $key = NULL)
这是可悲的不同数据库:: 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) {
所以这意味着'主'或'奴隶'或'默认'总是作为集合使用,但不是替代数据库/模式的关键,需要db_set_active('...“);和db_set_active();围绕着db_select。
由于在db_select的处理过程中很容易要求调用其他dbs(比如devel调用或者改变调用),所以这是不灵活的设计。改变这一呼吁:
return Database::getConnection($options['target'])->select($table, $alias, $options);
添加的关键参数(它已经只具备作为参数!!)需要的,但到目前为止,我现在可以看到不足。
http://drupal.org/node/18429也有一些代码示例,特别是如果您要动态配置数据库设置,即不在settings.php中进行硬编码。例如,如果您将数据库设置存储在settings.php以外的某个位置,则可以动态创建该数组并使用Database :: addConnectionInfo()建立数据库连接。 – sillygwailo 2011-01-29 23:16:44