27 lines
679 B
PHP
27 lines
679 B
PHP
<?php
|
|
class Database {
|
|
private $pdo;
|
|
|
|
public function __construct($config) {
|
|
$dsn = "pgsql:host={$config['host']};dbname={$config['dbname']}";
|
|
try {
|
|
$this->pdo = new PDO($dsn, $config['user'], $config['password'], [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
|
]);
|
|
} catch (PDOException $e) {
|
|
die('Connection failed: ' . $e->getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
public function getDefaultSchema() {
|
|
$query = "SELECT current_schema()";
|
|
$stmt = $this->pdo->query($query);
|
|
return $stmt->fetchColumn();
|
|
}
|
|
|
|
public function getPDO() {
|
|
return $this->pdo;
|
|
}
|
|
}
|