diff options
author | Andrew Dolgov <[email protected]> | 2013-05-07 15:36:14 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2013-05-07 15:36:14 +0400 |
commit | 82076ce53113be9cc053f8740356e7e1b81e5643 (patch) | |
tree | 5eba36805f593ec7dd0aad671b5bcca0ae01cf53 /classes/db/pgsql.php | |
parent | 66af65f14b4f3c670bb3f9ca7b1c80081f9281d1 (diff) | |
parent | 23923fb29b345c1eea5b70a6df4d30395425bf37 (diff) |
Merge branch 'master' into css-feedtree-counter
Conflicts:
tt-rss.css
Diffstat (limited to 'classes/db/pgsql.php')
-rw-r--r-- | classes/db/pgsql.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php new file mode 100644 index 000000000..4d860790b --- /dev/null +++ b/classes/db/pgsql.php @@ -0,0 +1,82 @@ +<?php +class Db_Pgsql implements IDb { + private $link; + + function connect($host, $user, $pass, $db, $port) { + $string = "dbname=$db user=$user"; + + if ($pass) { + $string .= " password=$pass"; + } + + if ($host) { + $string .= " host=$host"; + } + + if (is_numeric($port) && $port > 0) { + $string = "$string port=" . $port; + } + + $this->link = pg_connect($string); + + if (!$this->link) { + die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error()); + } + + $this->init(); + + return $this->link; + } + + function escape_string($s, $strip_tags = true) { + if ($strip_tags) $s = strip_tags($s); + + return pg_escape_string($s); + } + + function query($query, $die_on_error = true) { + $result = pg_query($query); + + if (!$result) { + $query = htmlspecialchars($query); // just in case + user_error("Query $query failed: " . ($this->link ? pg_last_error($this->link) : "No connection"), + $die_on_error ? E_USER_ERROR : E_USER_WARNING); + } + return $result; + } + + function fetch_assoc($result) { + return pg_fetch_assoc($result); + } + + + function num_rows($result) { + return pg_num_rows($result); + } + + function fetch_result($result, $row, $param) { + return pg_fetch_result($result, $row, $param); + } + + function close() { + return pg_close($this->link); + } + + function affected_rows($result) { + return pg_affected_rows($result); + } + + function last_error() { + return pg_last_error($this->link); + } + + function init() { + $this->query("set client_encoding = 'UTF-8'"); + pg_set_client_encoding("UNICODE"); + $this->query("set datestyle = 'ISO, european'"); + $this->query("set TIME ZONE 0"); + + return true; + } +} +?> |