You are here

public function FrxPDO::__construct in Forena Reports 7

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

Object constructor

Parameters

unknown_type $uri Database connection string.:

string $repos_path Path to location of data block definitions:

Overrides FrxDataProvider::__construct

File

plugins/FrxPDO.inc, line 22
General database engine used to do sql queries.

Class

FrxPDO
@file General database engine used to do sql queries.

Code

public function __construct($conf, $repos_path) {
  parent::__construct($conf, $repos_path);
  $uri = $conf['uri'];
  $this->debug = $conf['debug'];
  if ($uri) {

    // Test for PDO suport
    if (!class_exists('PDO')) {
      forena_error('PDO support not installed.', 'PDO support not installed.');
      return;
    }

    // Test for driver support
    @(list($prot, $c) = explode(':', $uri, 2));
    $drivers = PDO::getAvailableDrivers();
    if ($drivers && array_search($prot, $drivers) === FALSE) {
      $msg = 'PDO driver support for ' . $prot . ' not installed';
      forena_error($msg, $msg);
      return;
    }
    try {
      if (isset($conf['user'])) {
        $db = new PDO($uri, $conf['user'], $conf['password']);
      }
      else {
        $db = new PDO($uri);
      }
      $this->db = $db;
      if (!is_object($db)) {
        forena_error('Unknown error connecting to database ' . $uri);
      }
    } catch (PDOException $e) {
      forena_error('Unable to connect to database', $e
        ->getMessage());
    }
  }
  else {
    forena_error('No database connection string specified');
  }

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