You are here

public function FrxPostgres::__construct in Forena Reports 7.4

Same name and namespace in other branches
  1. 6.2 plugins/FrxPostgres.inc \FrxPostgres::__construct()
  2. 6 plugins/FrxPostgres.inc \FrxPostgres::__construct()
  3. 7 plugins/FrxPostgres.inc \FrxPostgres::__construct()
  4. 7.2 plugins/FrxPostgres.inc \FrxPostgres::__construct()
  5. 7.3 plugins/FrxPostgres.inc \FrxPostgres::__construct()

Object constructor

Parameters

unknown_type $uri Database connection string.:

string $repos_path Path to location of data block definitions:

Overrides FrxDataSource::__construct

File

plugins/FrxPostgres.inc, line 21
Postgres specific driver that takes advantage of native XML support

Class

FrxPostgres
@file Postgres specific driver that takes advantage of native XML support

Code

public function __construct($conf, $repos_path, $name) {
  parent::__construct($conf, $repos_path, $name);
  $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
        ->error('PHP Postgres support not installed.', 'PHP Postgres support not installed.');
      return;
    }
    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
        ->error('Unable to connect to database ' . $conf['title'], $e
        ->getMessage());
    }
  }
  else {
    $this
      ->error('No database connection string specified', 'No database connection: ' . print_r($conf, 1));
  }

  // Set up the stuff required to translate.
  $this->te = new FrxSyntaxEngine(FRX_SQL_TOKEN, ':', $this);
}