support pgsql in pdo

This commit is contained in:
Andrew Dolgov 2013-04-18 08:28:03 +04:00
parent 9ee90455b8
commit 73663db316
1 changed files with 20 additions and 1 deletions

View File

@ -3,10 +3,14 @@ class Db_PDO implements IDb {
private $pdo; private $pdo;
function connect($host, $user, $pass, $db, $port) { function connect($host, $user, $pass, $db, $port) {
$connstr = DB_TYPE . ":host=$host;dbname=$db;charset=utf8"; $connstr = DB_TYPE . ":host=$host;dbname=$db";
if (DB_TYPE == "mysql") $connstr .= ";charset=utf8";
try { try {
$this->pdo = new PDO($connstr, $user, $pass); $this->pdo = new PDO($connstr, $user, $pass);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->init();
} catch (PDOException $e) { } catch (PDOException $e) {
die($e->getMessage()); die($e->getMessage());
} }
@ -77,5 +81,20 @@ class Db_PDO implements IDb {
function last_error() { function last_error() {
return join(" ", $pdo->errorInfo()); return join(" ", $pdo->errorInfo());
} }
function init() {
switch (DB_TYPE) {
case "pgsql":
$this->query("set client_encoding = 'UTF-8'");
$this->query("set datestyle = 'ISO, european'");
$this->query("set TIME ZONE 0");
case "mysql":
$this->query("SET time_zone = '+0:0'");
return;
}
return true;
}
} }
?> ?>