]> git.wh0rd.org - tt-rss.git/blobdiff - classes/db/pgsql.php
remove some redundant php closing tags
[tt-rss.git] / classes / db / pgsql.php
index 4d860790b1d1da4306eeaf2f125c53b12b04a6c3..98fab6beae62c36a4034cf9a70a39c46a6fbdfc9 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 class Db_Pgsql implements IDb {
        private $link;
+       private $last_error;
 
        function connect($host, $user, $pass, $db, $port) {
                $string = "dbname=$db user=$user";
@@ -20,7 +21,8 @@ class Db_Pgsql implements IDb {
                $this->link = pg_connect($string);
 
                if (!$this->link) {
-                       die("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
+                       print("Unable to connect to database (as $user to $host, database $db):" . pg_last_error());
+                       exit(102);
                }
 
                $this->init();
@@ -35,11 +37,14 @@ class Db_Pgsql implements IDb {
        }
 
        function query($query, $die_on_error = true) {
-               $result = pg_query($query);
+               $result = @pg_query($this->link, $query);
 
                if (!$result) {
+                       $this->last_error = @pg_last_error($this->link);
+
+                       @pg_query($this->link, "ROLLBACK");
                        $query = htmlspecialchars($query); // just in case
-                       user_error("Query $query failed: " . ($this->link ? pg_last_error($this->link) : "No connection"),
+                       user_error("Query $query failed: " . ($this->link ? $this->last_error : "No connection"),
                                $die_on_error ? E_USER_ERROR : E_USER_WARNING);
                }
                return $result;
@@ -70,13 +75,17 @@ class Db_Pgsql implements IDb {
                return pg_last_error($this->link);
        }
 
+       function last_query_error() {
+               return $this->last_error;
+       }
+
        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");
+               $this->query("set cpu_tuple_cost = 0.5");
 
                return true;
        }
-}
-?>
+}
\ No newline at end of file