]>
git.wh0rd.org - tt-rss.git/blob - classes/db/pgsql.php
5e43b9110ab83609b2edeb804092188a12418595
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($s);
37 function query($query, $die_on_error = true) {
38 $result = @pg_query
($this->link
, $query);
41 $error = @pg_last_error
($this->link
);
43 @pg_query
($this->link
, "ROLLBACK");
44 $query = htmlspecialchars($query); // just in case
45 user_error("Query $query failed: " . ($this->link ?
$error : "No connection"),
46 $die_on_error ? E_USER_ERROR
: E_USER_WARNING
);
51 function fetch_assoc($result) {
52 return pg_fetch_assoc($result);
56 function num_rows($result) {
57 return pg_num_rows($result);
60 function fetch_result($result, $row, $param) {
61 return pg_fetch_result($result, $row, $param);
65 return pg_close($this->link
);
68 function affected_rows($result) {
69 return pg_affected_rows($result);
72 function last_error() {
73 return pg_last_error($this->link
);
77 $this->query("set client_encoding = 'UTF-8'");
78 pg_set_client_encoding("UNICODE");
79 $this->query("set datestyle = 'ISO, european'");
80 $this->query("set TIME ZONE 0");
81 $this->query("set cpu_tuple_cost = 0.1");