2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * PostgreSQL Database Layer (DbPostgreSql.php)
28 require_once(ISSO
. '/Db.php');
31 * PostgreSQL Database Layer
33 * This framework is a function wrapper for PostgreSQL functions so we can have
34 * better error reporting and query reporting.
37 * @copyright Copyright (c)2005 - 2008, Blue Static
41 class BSDbPostgreSql
extends BSDb
44 * Port number to connect to
50 * Sets the port number for the connection
52 * @param integer Port number
54 public function setPort($port)
62 protected function _connect($server, $user, $password, $database)
64 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
68 * Wrapper: pg_escape_string
70 protected function _escapeString()
72 return pg_escape_string($string);
76 * Wrapper/no support: error string
78 protected function _errorString()
82 return pg_result_error($this->result);
85 return pg_last_error($this->dblink);
89 * Not supported: error numbers
91 protected function _errorNumber()
99 public function insertId($table, $field)
101 return $this->queryFirst("SELECT last_value FROM {$table
}_{$field
}_seq
")->fetchObject()->last_value;
104 protected function _insertId()
108 * Wrapper: pg_affected_rows
110 protected function _affectedRows($result)
112 return pg_affected_rows($result);
116 * Starts a database transaction
118 public function begin()
120 $this->query("BEGIN
");
124 * Reverts a transaction back to a given savepoint
126 public function rollback()
128 $this->query("ROLLBACK
");
132 * Commits a database transaction
134 public function commit()
136 $this->query("COMMIT
");
140 * Returns the error number
142 * @return integer Error number
144 public function _errorNumber()
150 * Returns the error string
152 * @return string Error string
154 public function _errorString()
156 return pg_last_error($this->dblink);
163 * This class holds result information for a database result
166 * @copyright Copyright (c)2005 - 2008, Blue Static
170 class BSDbPostgreSqlResult extends BSDbResult
173 * Wrapper: pg_fetch_assoc
175 protected function _fetchAssocArray($result)
177 return pg_fetch_assoc($result);
181 * Wrapper: pg_fetch_row
183 protected function _fetchRowArray($result)
185 return pg_fetch_row($result);
189 * Wrapper: pg_fetch_object
191 public function _fetchObject($result)
193 return pg_fetch_object($result);
197 * Wrapper: pg_free_result
199 protected function _freeResult($result)
201 pg_free_result($result);
205 * Wrapper: pg_num_rows
207 protected function _numRows($result)
209 return pg_num_rows($result);