public function FrxPDO::__construct in Forena Reports 7.5
Object constructor
Parameters
unknown_type $uri Database connection string.:
string $repos_path Path to location of data block definitions:
Overrides FrxDataSource::__construct
File
- src/
Driver/ FrxPDO.php, line 22 - General database engine used to do sql queries.
Class
Namespace
Drupal\forena\DriverCode
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')) {
$this
->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();
$this->db_type = $prot;
if ($drivers && array_search($prot, $drivers) === FALSE) {
$msg = 'PDO driver support for ' . $prot . ' not installed';
$this
->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)) {
$this
->error('Unknown error connecting to database ' . $uri);
}
} catch (\PDOException $e) {
$this
->error('Unable to connect to database', $e
->getMessage());
}
if ($this->db) {
$this->db
->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
}
}
else {
$this
->error('No database connection string specified');
}
// Set up the stuff required to translate.
$this->te = new SQLReplacer($this);
}