function ChadoDatabaseConnection::__construct

3.x ChadoDatabaseConnection.inc ChadoDatabaseConnection::__construct(array $connection_options = array())

A replacement constructor for DatabaseConnection_pgsql::__construct.

The primary purpose for overiding the constructor is to dynamically add a set of prefixes for replacing. This will allow Chado tables to be prefixed with the 'chado.' schema prefix. The alternative to overridding the DatabaseConnection_pgsql is to ask the end-user to add a prefix entry for every Chado table and custom table they create. That's not very manageable.

File

tripal_chado/includes/ChadoDatabaseConnection.inc, line 27

Class

ChadoDatabaseConnection
Overrides the DatabaseConnection_pgsql.

Code

function __construct(array $connection_options = array()) {
  parent::__construct($connection_options);


  // Get the list of prefix search and replace that are set in the
  // settings.php file. We'll need those later.
  $psearch = $this->prefixSearch;
  $preplace = $this->prefixReplace;

  // Reset the prefix serach and replace
  $this->prefixSearch = array();
  $this->prefixReplace = array();

  $tables = chado_get_table_names(TRUE);
  foreach ($tables as $table) {
    $this->prefixSearch[] = '{' . $table . '}';
    $this->prefixReplace[] = 'chado.' . $table;
  }
  $this->prefixSearch = array_merge($this->prefixSearch, $psearch);
  $this->prefixReplace = array_merge($this->prefixReplace, $preplace);
}