You are here

public function FrxPostgres::__construct in Forena Reports 8

Object constructor

Parameters

string $name : Database connection name

array $conf: Configuration data

DataFileSystem $fileSystem : File system ojbect used to get files.

Overrides DriverBase::__construct

File

src/FrxPlugin/Driver/FrxPostgres.php, line 37
Postgres specific driver that takes advantage of native XML support

Class

FrxPostgres
Class FrxPostgres

Namespace

Drupal\forena\FrxPlugin\Driver

Code

public function __construct($name, $conf, DataFileSystem $fileSystem) {
  parent::__construct($name, $conf, $fileSystem);
  $this->use_postgres_xml = FALSE;
  $uri = $conf['uri'];
  $this->db_type = 'postgres';
  if (!empty($conf['password'])) {
    $uri = trim($uri) . ' password=' . $conf['password'];
  }
  $this->debug = @$conf['debug'];
  if (isset($conf['postgres_xml'])) {
    $this->use_postgres_xml = $conf['postgres_xml'];
  }
  if ($uri) {

    // Test for postgres suport
    if (!is_callable('pg_connect')) {
      $this
        ->app()
        ->error('PHP Postgres support not installed.', 'PHP Postgres support not installed.');
      return NULL;
    }
    try {
      $db = pg_connect($uri);
      if (isset($conf['search path'])) {
        @pg_query($db, "SET search_path=" . $conf['search path']);
      }
      $this->db = $db;
    } catch (\Exception $e) {
      $this
        ->app()
        ->error('Unable to connect to database ' . $conf['title'], $e
        ->getMessage());
    }
  }
  else {
    $this
      ->app()
      ->error('No database connection string specified', 'No database connection: ' . print_r($conf, 1));
  }

  // Set up the stuff required to translate.
  $this->te = new SQLReplacer($this);
}