2 deleted 20 characters in body
source | link

issue is that db_set_active just sets active key in some array and doesn't do any connection. when you do db_select or any other query only then it connects.

your second code is good. also you could do something like this:

  db_set_active('external');
  try {
   //check connection
   db_select("select nid from node limit 1");
  }
  catch (PDOException $e) {
      //error. set default back
      db_set_active('default');
  }

as you know how to check if connection is there now you just need extra logic what todo when connection cannot be established

issue is that db_set_active just sets active key in some array and doesn't do any connection. when you do db_select or any other query only then it connects.

your second code is good. also you could do something like this:

  db_set_active('external');
  try {
   //check connection
   db_select("select nid from node limit 1");
  }
  catch (PDOException $e) {
      //error. set default back
      db_set_active('default');
  }

as you know how to check if connection is there now you just need extra logic what todo when connection cannot be established

issue is that db_set_active just sets active key in some array and doesn't do any connection. when you do db_select or any other query only then it connects.

your second code is good. also you could do something like this:

  db_set_active('external');
  try {
   //check connection
   db_select("select 1");
  }
  catch (PDOException $e) {
      //error. set default back
      db_set_active('default');
  }

as you know how to check if connection is there now you just need extra logic what todo when connection cannot be established

1
source | link

issue is that db_set_active just sets active key in some array and doesn't do any connection. when you do db_select or any other query only then it connects.

your second code is good. also you could do something like this:

  db_set_active('external');
  try {
   //check connection
   db_select("select nid from node limit 1");
  }
  catch (PDOException $e) {
      //error. set default back
      db_set_active('default');
  }

as you know how to check if connection is there now you just need extra logic what todo when connection cannot be established