]>
git.wh0rd.org - tt-rss.git/blob - classes/db/pgsql.php
2 class Db_Pgsql
implements IDb
{
6 function connect($host, $user, $pass, $db, $port) {
7 $string = "dbname=$db user=$user";
10 $string .= " password=$pass";
14 $string .= " host=$host";
17 if (is_numeric($port) && $port > 0) {
18 $string = "$string port=" . $port;
21 $this->link
= pg_connect($string);
24 die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
32 function escape_string($s, $strip_tags = true) {
33 if ($strip_tags) $s = strip_tags($s);
35 return pg_escape_string($s);
38 function query($query, $die_on_error = true) {
39 $result = @pg_query
($this->link
, $query);
42 $this->last_error
= @pg_last_error
($this->link
);
44 @pg_query
($this->link
, "ROLLBACK");
45 $query = htmlspecialchars($query); // just in case
46 user_error("Query $query failed: " . ($this->link ?
$this->last_error
: "No connection"),
47 $die_on_error ? E_USER_ERROR
: E_USER_WARNING
);
52 function fetch_assoc($result) {
53 return pg_fetch_assoc($result);
57 function num_rows($result) {
58 return pg_num_rows($result);
61 function fetch_result($result, $row, $param) {
62 return pg_fetch_result($result, $row, $param);
66 return pg_close($this->link
);
69 function affected_rows($result) {
70 return pg_affected_rows($result);
73 function last_error() {
74 return pg_last_error($this->link
);
77 function last_query_error() {
78 return $this->last_error
;
82 $this->query("set client_encoding = 'UTF-8'");
83 pg_set_client_encoding("UNICODE");
84 $this->query("set datestyle = 'ISO, european'");
85 $this->query("set TIME ZONE 0");
86 $this->query("set cpu_tuple_cost = 0.5");