db = $db); } public function close() { return pg_close($this->db); } public function query($query) { $res = pg_query($this->db, $query) or die("Error: wrong SQL query #$query#"); return $res; } public function fetchAllArray($query, $type = PGSQL_ASSOC) { $res = $this->query($query); $rows = array(); while ($row = pg_fetch_array($res, NULL, $type)) { $rows[] = $this->clean($row); } pg_free_result($res); return ($rows) ? $rows : array(); } public function affectedRows() { return pg_affected_rows($this->db); } private function clean($row) { foreach ($row as $key => $value) { $row[$key] = trim($value); } return $row; } public function fetchOneArray($query, $type = PGSQL_ASSOC) { $res = $this->query($query); $row = pg_fetch_array($res, NULL, $type); pg_free_result($res); return ($row) ? $this->clean($row) : array(); } function getNextId($seq) { $result = $this->fetchOneArray("SELECT nextval('$seq')"); return $result['nextval']; } }