public function FrxPDO::__construct in Forena Reports 7.3
Same name and namespace in other branches
- 6.2 plugins/FrxPDO.inc \FrxPDO::__construct()
- 6 plugins/FrxPDO.inc \FrxPDO::__construct()
- 7 plugins/FrxPDO.inc \FrxPDO::__construct()
- 7.2 plugins/FrxPDO.inc \FrxPDO::__construct()
- 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 FrxDataSource::__construct
File
- plugins/
FrxPDO.inc, line 21 - 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, $name) {
parent::__construct($conf, $repos_path, $name);
$uri = $conf['uri'];
$this->debug = $conf['debug'];
if ($uri) {
// Test for PDO suport
if (!class_exists('PDO')) {
FrxReportGenerator::instance()
->error('PDO support not installed.', 'PDO support not installed.');
return;
}
$options = array();
if (@$conf['mysql_charset']) {
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $conf['mysql_charset'],
);
}
// 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';
FrxReportGenerator::instance()
->error($msg, $msg);
return;
}
try {
if (isset($conf['user'])) {
$db = new PDO($uri, $conf['user'], @$conf['password'], $options);
}
else {
$db = new PDO($uri, NULL, NULL, $options);
}
$this->db = $db;
if (!is_object($db)) {
FrxReportGenerator::instance()
->error('Unknown error connecting to database ' . $uri);
}
} catch (PDOException $e) {
FrxReportGenerator::instance()
->error('Unable to connect to database', $e
->getMessage());
}
}
else {
FrxReportGenerator::instance()
->error('No database connection string specified');
}
// Set up the stuff required to translate.
$this->te = new FrxSyntaxEngine(FRX_SQL_TOKEN, ':', $this);
}