Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello
I'm implementing drupal in such a fashion that multiple (non-drupal) databases are queried.
I'm having a problem getting the FALSE return value if a db_set_active($name) is attempted when $name does not exist in the setting file . Essentially, the lack of a FALSE return value prevents us from knowing if we connected.
This is might be a bug in the core function or my usage of postgres. Currently I simply solve it through a function that was making the connection
sub connect_my_db($name=NULL){
#reset to Drupal. call it after finishing with secondary DB
if (empty($name){
db_set_active('default');
}
global $db_url;
if (empty ($db_url[$name])){
drupal_set_message('The public database is unavailable at the time.','error','FALSE');
return FALSE;
}else {
db_set_active($name);
return TRUE;
}
}
I 've tested that this indeed works with databases not/wrongly specified in the settings file.
cheers
alexie
Comments