]>
git.wh0rd.org - tt-rss.git/blob - classes/db/pgsql.php
0f38fb8cb5d124fd47cbcee815d89a4e6cf98d05
2 class Db_Pgsql
implements IDb
{
5 function connect($host, $user, $pass, $db, $port) {
6 $string = "dbname=$db user=$user";
9 $string .= " password=$pass";
13 $string .= " host=$host";
16 if (is_numeric($port) && $port > 0) {
17 $string = "$string port=" . $port;
20 $this->link
= pg_connect($string);
23 die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
31 function escape_string($s, $strip_tags = true) {
32 if ($strip_tags) $s = strip_tags($s);
34 return pg_escape_string($this->link
, $s);
37 function query($query, $die_on_error = true) {
38 $result = pg_query($this->link
, $query);
41 $query = htmlspecialchars($query); // just in case
43 die("Query <i>$query</i> failed [$result]: " . ($this->link ?
pg_last_error($this->link
) : "No connection"));
49 function fetch_assoc($result) {
50 return pg_fetch_assoc($result);
54 function num_rows($result) {
55 return pg_num_rows($result);
58 function fetch_result($result, $row, $param) {
59 return pg_fetch_result($result, $row, $param);
63 return pg_close($this->link
);
66 function affected_rows($result) {
67 return pg_affected_rows($result);
70 function last_error() {
71 return pg_last_error($this->link
);
75 $this->query("set client_encoding = 'UTF-8'");
76 pg_set_client_encoding("UNICODE");
77 $this->query("set datestyle = 'ISO, european'");
78 $this->query("set TIME ZONE 0");