2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 ©2002 - [#]year[#], Blue Static
42 class BSDbPostgreSql
extends BSDb
45 * Command mapping list
48 protected $commands = array(
49 'pconnect' => '$this->command_pg_pconnect',
50 'connect' => '$this->command_pg_connect',
51 'query' => 'pg_query',
52 'error_num' => '$this->command_error_num',
53 'error_str' => '$this->command_error_str',
54 'escape_string' => '$this->command_pg_escape_string',
55 'escape_binary' => 'pg_escape_bytea',
56 'unescape_binary' => 'pg_unescape_bytea',
57 'fetch_assoc' => 'pg_fetch_assoc',
58 'fetch_row' => 'pg_fetch_row',
59 'fetch_object' => 'pg_fetch_object',
60 'free_result' => 'pg_free_result',
61 'insert_id' => '%link', // how do we support this...?
62 'num_rows' => 'pg_num_rows',
63 'affected_rows' => 'pg_affected_rows'
67 * Port number to connect to
72 // ###################################################################
74 * Sets the port number for the connection
76 * @param integer Port number
78 public function setPort($port)
83 // ###################################################################
87 protected function _connect($server, $user, $password, $database)
89 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
92 // ###################################################################
94 * Wrapper: pg_pconnect
96 protected function _pConnect($server, $user, $password, $database)
98 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
101 // ###################################################################
103 * Wrapper: pg_escape_string
105 protected function _escapeString()
107 return pg_escape_string($string);
110 // ###################################################################
112 * Wrapper/no support: error string
114 protected function _errorString()
118 return pg_result_error($this->result
);
121 return pg_last_error($this->dblink
);
124 // ###################################################################
126 * Not supported: error numbers
128 protected function _errorNumber()
133 // ###################################################################
137 public function insertId($table, $field)
139 $temp = $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq");
140 return $temp['last_value'];
143 protected function _insertId()
148 // ###################################################################
150 * Wrapper: pg_fetch_assoc
152 protected function _fetchAssocArray($result)
154 return pg_fetch_assoc($result);
157 // ###################################################################
159 * Wrapper: pg_fetch_row
161 protected function _fetchRowArray($result)
163 return pg_fetch_row($result);
166 // ###################################################################
168 * Wrapper: pg_fetch_object
170 public function _fetchObject($result)
172 return pg_fetch_object($result);
175 // ###################################################################
177 * Wrapper: pg_free_result
179 protected function _freeResult($result)
181 pg_free_result($result);
184 // ###################################################################
186 * Wrapper: pg_num_rows
188 protected function _numRows($result)
190 return pg_num_rows($result);
193 // ###################################################################
195 * Wrapper: pg_affected_rows
197 protected function _affectedRows($result)
199 return PG_AFFECTED_ROWS($result);
202 // ###################################################################
204 * Starts a database transaction
206 public function transaction_start()
208 $this->query("BEGIN");
211 // ###################################################################
213 * Saves current transaction steps as a savepoint
215 * @param string Named savepoint
217 public function transaction_savepoint($name)
219 $this->query("SAVEPOINT $name");
222 // ###################################################################
224 * Reverts a transaction back to a given savepoint
226 * @param string Named savepoint
228 public function transaction_rollback($name = null
)
230 $this->query("ROLLBACK" . ($name != null ?
" TO $name" : ""));
233 // ###################################################################
235 * Commits a database transaction
237 public function transaction_commit()
239 $this->query("COMMIT");
243 /*=====================================================================*\
244 || ###################################################################
247 || ###################################################################
248 \*=====================================================================*/