function tripal_db_persistent_chado

1.x tripal_core_chado.api.inc tripal_db_persistent_chado()

Instantiate or Return a persistent chado connection. This should not be confused with PHP persistent connections. Here we use the drupal db_connect function to

NOTE: cannot use $active_db since a new connection is created each time db_set_active() is called

Return value

A postgresql connection object which can be used by pg_prepare, pg_execute, etc.

13 calls to tripal_db_persistent_chado()
tripal_core_chado_delete in tripal_core/api/tripal_core_chado.api.inc
Provides a generic function for deleting a record(s) from any chado table
tripal_core_chado_insert in tripal_core/api/tripal_core_chado.api.inc
Provides a generic routine for inserting into any Chado table
tripal_core_chado_select in tripal_core/api/tripal_core_chado.api.inc
Provides a generic routine for selecting data from a Chado table
tripal_core_chado_update in tripal_core/api/tripal_core_chado.api.inc
Provides a generic routine for updating into any Chado table
tripal_core_init in tripal_core/tripal_core.module
Implements hook_init(). Used to set the search_path, create default content and set default variables.

... See full list

File

tripal_core/api/tripal_core_chado.api.inc, line 3205
The Tripal Core API

Code

function tripal_db_persistent_chado() {
  global $db_url;
  global $persistent_chado;

  // get connection if it already exists otherwise we need to set it
  if ($persistent_chado) {
    return $persistent_chado;
  }
  else {
    if (is_array($db_url) && isset($db_url['chado'])) {
      $connection = db_connect($db_url['chado']);
      if (!$connection) {
        watchdog('tripal_core', "Could not create persistant connection", array(), WATCHDOG_ERROR);
        return FALSE;
      }
      $persistent_chado = $connection;
    }
    else {
      if (is_array($db_url)) {
        $connection = db_connect($db_url['default']);
      }
      else {
        $connection = db_connect($db_url);
      }
      if (!$connection) {
        $persistent_chado = NULL;
        watchdog('tripal_core', "Could not create persistant connection", array(), WATCHDOG_ERROR);
        return FALSE;
      }
      $persistent_chado = $connection;
    }
    return $connection;
  }
  return FALSE;
}