]>
git.wh0rd.org - tt-rss.git/blob - classes/db/pgsql.php
c9ec338876dd2e150a2e6b5ca2e18c679d9b6a50
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());
29 function escape_string($s, $strip_tags = true) {
30 if ($strip_tags) $s = strip_tags($s);
32 return pg_escape_string($this->link
, $s);
35 function query($query, $die_on_error = true) {
36 $result = pg_query($this->link
, $query);
39 $query = htmlspecialchars($query); // just in case
41 die("Query <i>$query</i> failed [$result]: " . ($this->link ?
pg_last_error($this->link
) : "No connection"));
47 function fetch_assoc($result) {
48 return pg_fetch_assoc($result);
52 function num_rows($result) {
53 return pg_num_rows($result);
56 function fetch_result($result, $row, $param) {
57 return pg_fetch_result($result, $row, $param);
61 return pg_close($this->link
);
64 function affected_rows($result) {
65 return pg_affected_rows($result);
68 function last_error() {
69 return pg_last_error($this->link
);
73 $this->query("set client_encoding = 'UTF-8'");
74 pg_set_client_encoding("UNICODE");
75 $this->query("set datestyle = 'ISO, european'");
76 $this->query("set TIME ZONE 0");