2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 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)2002 - 2007, Blue Static
41 class BSDbPostgreSql
extends BSDb
44 * Port number to connect to
49 // ###################################################################
51 * Sets the port number for the connection
53 * @param integer Port number
55 public function setPort($port)
60 // ###################################################################
64 protected function _connect($server, $user, $password, $database)
66 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
69 // ###################################################################
71 * Wrapper: pg_escape_string
73 protected function _escapeString()
75 return pg_escape_string($string);
78 // ###################################################################
80 * Wrapper/no support: error string
82 protected function _errorString()
86 return pg_result_error($this->result
);
89 return pg_last_error($this->dblink
);
92 // ###################################################################
94 * Not supported: error numbers
96 protected function _errorNumber()
101 // ###################################################################
103 * Starts a database transaction
105 public function start()
107 $this->query("BEGIN");
110 // ###################################################################
112 * Reverts a transaction back to a given savepoint
114 public function rollback()
116 $this->query("ROLLBACK");
119 // ###################################################################
121 * Commits a database transaction
123 public function commit()
125 $this->query("COMMIT");
128 // ###################################################################
130 * Returns the error number
132 * @return integer Error number
134 public function _errorNumber()
139 // ###################################################################
141 * Returns the error string
143 * @return string Error string
145 public function _errorString()
147 return pg_last_error($this->dblink
);
154 * This class holds result information for a database result
157 * @copyright Copyright (c)2002 - 2007, Blue Static
161 class BSDbPostgreSqlResult
extends BSDbResult
163 // ###################################################################
167 public function insertId($table, $field)
169 return $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq")->fetchObject()->last_value
;
172 protected function _insertId()
175 // ###################################################################
177 * Wrapper: pg_fetch_assoc
179 protected function _fetchAssocArray($result)
181 return pg_fetch_assoc($result);
184 // ###################################################################
186 * Wrapper: pg_fetch_row
188 protected function _fetchRowArray($result)
190 return pg_fetch_row($result);
193 // ###################################################################
195 * Wrapper: pg_fetch_object
197 public function _fetchObject($result)
199 return pg_fetch_object($result);
202 // ###################################################################
204 * Wrapper: pg_free_result
206 protected function _freeResult($result)
208 pg_free_result($result);
211 // ###################################################################
213 * Wrapper: pg_num_rows
215 protected function _numRows($result)
217 return pg_num_rows($result);
220 // ###################################################################
222 * Wrapper: pg_affected_rows
224 protected function _affectedRows($result)
226 return pg_affected_rows($result);