]>
git.wh0rd.org - tt-rss.git/blob - classes/db/pgsql.php
39ed181d7a725e9e71d1b8d666ec534a912be1d5
3 class Db_Pgsql
extends Db_Abstract
5 public function connect($host, $user, $pass, $db)
7 $string = "dbname=$db user=$user";
10 $string .= " password=$pass";
14 $string .= " host=$host";
17 if (defined('DB_PORT')) {
18 $string = "$string port=" . DB_PORT
;
21 $link = pg_connect($string);
24 die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
27 $this->dbconn
= $link;
31 public function init()
33 pg_query($this->dbconn
, "set client_encoding = 'UTF-8'");
34 pg_set_client_encoding("UNICODE");
35 pg_query($this->dbconn
, "set datestyle = 'ISO, european'");
36 pg_query($this->dbconn
, "set TIME ZONE 0");
39 public function escape_string($s, $strip_tags = true)
41 if ($strip_tags) $s = strip_tags($s);
42 return pg_escape_string($s);
45 public function query($query, $die_on_error = true)
47 $result = pg_query($this->dbconn
, $query);
49 $query = htmlspecialchars($query); // just in case
51 die("Query <i>$query</i> failed [$result]: " . ($this->dbconn ?
pg_last_error($this->dbconn
) : "No connection"));
57 public function fetch_assoc($result) {
58 return pg_fetch_assoc($result);
61 public function num_rows($result) {
62 return pg_num_rows($result);
65 public function fetch_result($result, $row, $param) {
66 return pg_fetch_result($result, $row, $param);
69 public function close() {
70 return pg_close($this->dbconn
);
73 public function affected_rows($result) {
74 return pg_affected_rows($result);
77 public function last_error() {
78 return pg_last_error($this->dbconn
);