]> src.bluestatic.org Git - isso.git/blob - DbPostgreSql.php
Fixing another call to BSApp::GetType() and switching to using the ::Registry()
[isso.git] / DbPostgreSql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * PostgreSQL Database Layer (DbPostgreSql.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/Db.php');
29
30 /**
31 * PostgreSQL Database Layer
32 *
33 * This framework is a function wrapper for PostgreSQL functions so we can have
34 * better error reporting and query reporting.
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2002 - 2007, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSDbPostgreSql extends BSDb
42 {
43 /**
44 * Port number to connect to
45 * @var integer
46 */
47 private $port = 5432;
48
49 // ###################################################################
50 /**
51 * Sets the port number for the connection
52 *
53 * @param integer Port number
54 */
55 public function setPort($port)
56 {
57 $this->port = $port;
58 }
59
60 // ###################################################################
61 /**
62 * Wrapper: pg_connect
63 */
64 protected function _connect($server, $user, $password, $database)
65 {
66 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
67 }
68
69 // ###################################################################
70 /**
71 * Wrapper: pg_escape_string
72 */
73 protected function _escapeString()
74 {
75 return pg_escape_string($string);
76 }
77
78 // ###################################################################
79 /**
80 * Wrapper/no support: error string
81 */
82 protected function _errorString()
83 {
84 if ($this->result)
85 {
86 return pg_result_error($this->result);
87 }
88
89 return pg_last_error($this->dblink);
90 }
91
92 // ###################################################################
93 /**
94 * Not supported: error numbers
95 */
96 protected function _errorNumber()
97 {
98 return -1;
99 }
100
101 // ###################################################################
102 /**
103 * Overload: insertId
104 */
105 public function insertId($table, $field)
106 {
107 $temp = $this->queryFirst("SELECT last_value FROM {$table}_{$field}_seq");
108 return $temp['last_value'];
109 }
110
111 protected function _insertId()
112 {
113 // we never get here
114 }
115
116 // ###################################################################
117 /**
118 * Wrapper: pg_fetch_assoc
119 */
120 protected function _fetchAssocArray($result)
121 {
122 return pg_fetch_assoc($result);
123 }
124
125 // ###################################################################
126 /**
127 * Wrapper: pg_fetch_row
128 */
129 protected function _fetchRowArray($result)
130 {
131 return pg_fetch_row($result);
132 }
133
134 // ###################################################################
135 /**
136 * Wrapper: pg_fetch_object
137 */
138 public function _fetchObject($result)
139 {
140 return pg_fetch_object($result);
141 }
142
143 // ###################################################################
144 /**
145 * Wrapper: pg_free_result
146 */
147 protected function _freeResult($result)
148 {
149 pg_free_result($result);
150 }
151
152 // ###################################################################
153 /**
154 * Wrapper: pg_num_rows
155 */
156 protected function _numRows($result)
157 {
158 return pg_num_rows($result);
159 }
160
161 // ###################################################################
162 /**
163 * Wrapper: pg_affected_rows
164 */
165 protected function _affectedRows($result)
166 {
167 return pg_affected_rows($result);
168 }
169
170 // ###################################################################
171 /**
172 * Starts a database transaction
173 */
174 public function start()
175 {
176 $this->query("BEGIN");
177 }
178
179 // ###################################################################
180 /**
181 * Reverts a transaction back to a given savepoint
182 */
183 public function rollback()
184 {
185 $this->query("ROLLBACK");
186 }
187
188 // ###################################################################
189 /**
190 * Commits a database transaction
191 */
192 public function commit()
193 {
194 $this->query("COMMIT");
195 }
196
197 // ###################################################################
198 /**
199 * Returns the error number
200 *
201 * @return integer Error number
202 */
203 public function _errorNumber()
204 {
205 return -1;
206 }
207
208 // ###################################################################
209 /**
210 * Returns the error string
211 *
212 * @return string Error string
213 */
214 public function _errorString()
215 {
216 return pg_last_error($this->dblink);
217 }
218 }
219
220 ?>