]> git.wh0rd.org - tt-rss.git/blobdiff - classes/db/pgsql.php
remove $link
[tt-rss.git] / classes / db / pgsql.php
index 87c2abefddd896d6f1be1d4f83046f6f72c1b0f8..0cb737978aef800c0b622becb29b561e87f65171 100644 (file)
@@ -23,23 +23,24 @@ class Db_Pgsql implements IDb {
                        die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
                }
 
+               $this->init();
+
                return $this->link;
        }
 
        function escape_string($s, $strip_tags = true) {
                if ($strip_tags) $s = strip_tags($s);
 
-               return pg_escape_string($this->link, $s);
+               return pg_escape_string( $s);
        }
 
        function query($query, $die_on_error = true) {
-               $result = pg_query($this->link, $query);
+               $result = pg_query( $query);
 
                if (!$result) {
                        $query = htmlspecialchars($query); // just in case
-                       if ($die_on_error) {
-                               die("Query <i>$query</i> failed [$result]: " . ($this->link ? pg_last_error($this->link) : "No connection"));
-                       }
+                       user_error("Query $query failed: " . ($this->link ? pg_last_error($this->link) : "No connection"),
+                               $die_on_error ? E_USER_ERROR : E_USER_WARNING);
                }
                return $result;
        }
@@ -69,5 +70,13 @@ class Db_Pgsql implements IDb {
                return pg_last_error($this->link);
        }
 
+       function init() {
+               $this->query("set client_encoding = 'UTF-8'");
+               pg_set_client_encoding("UNICODE");
+               $this->query("set datestyle = 'ISO, european'");
+               $this->query("set TIME ZONE 0");
+
+               return true;
+       }
 }
 ?>