Give all the instance variables visibility tags
[isso.git] / db_postgresql.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] 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 Abstraction Layer
24 * db_postgresql.php
25 *
26 * @package ISSO
27 */
28
29 $this->load('db', null);
30
31 /**
32 * PostgreSQL Database Abstraction Layer
33 *
34 * This framework is a function wrapper for PostgresQL functions so we can have
35 * better error reporting and query reporting.
36 *
37 * @author Iris Studios, Inc.
38 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
39 * @version $Revision$
40 * @package ISSO
41 *
42 */
43 class DB_PostgreSQL extends DB_Abstract
44 {
45 /**
46 * Command mapping list
47 * @var array
48 * @access private
49 */
50 var $commands = array(
51 'pconnect' => '$this->command_pg_pconnect',
52 'connect' => '$this->command_pg_connect',
53 'query' => 'pg_query',
54 'error_num' => '$this->command_error_num',
55 'error_str' => '$this->command_error_str',
56 'escape_string' => '$this->command_pg_escape_string',
57 'fetch_assoc' => 'pg_fetch_assoc',
58 'fetch_object' => 'pg_fetch_object',
59 'free_result' => 'pg_free_result',
60 'insert_id' => '%link', // how do we support this...?
61 'num_rows' => 'pg_num_rows',
62 'affected_rows' => 'pg_affected_rows'
63 );
64
65 /**
66 * Port number to connect to
67 * @var integer
68 * @access public
69 */
70 var $port = 5432;
71
72 // ###################################################################
73 /**
74 * Constructor
75 */
76 function __construct(&$registry)
77 {
78 parent::__construct($registry);
79 }
80
81 // ###################################################################
82 /**
83 * (PHP 4) Constructor
84 */
85 function DB_PostgreSQL(&$registry)
86 {
87 $this->__construct($registry);
88 }
89
90 // ###################################################################
91 /**
92 * Wrapper: pg_connect
93 *
94 * @access protected
95 *
96 * @param string Server name
97 * @param string User name
98 * @param string Password
99 * @param string Database
100 *
101 * @return integer DB-Link
102 */
103 function command_pg_connect($server, $user, $password, $database)
104 {
105 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
106 }
107
108 // ###################################################################
109 /**
110 * Wrapper: pg_pconnect
111 *
112 * @access protected
113 *
114 * @param string Server name
115 * @param string User name
116 * @param string Password
117 * @param string Database
118 *
119 * @return integer DB-Link
120 */
121 function command_pg_pconnect($server, $user, $password, $database)
122 {
123 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
124 }
125
126 // ###################################################################
127 /**
128 * Wrapper: pg_escape_string
129 *
130 * @access protected
131 *
132 * @param integer DB-Link (unused)
133 * @param string Raw string
134 *
135 * @return string Escaped string
136 */
137 function command_pg_escape_string($link, $string)
138 {
139 return pg_escape_string($string);
140 }
141
142 // ###################################################################
143 /**
144 * Wrapper/no support: error string
145 *
146 * @access protected
147 *
148 * @param integer DB-Link
149 *
150 * @return string Error string
151 */
152 function command_error_str($link)
153 {
154 if ($this->result)
155 {
156 return pg_result_error($this->result);
157 }
158
159 return pg_last_error($link);
160 }
161
162 // ###################################################################
163 /**
164 * Not supported: error numbers
165 *
166 * @access protected
167 *
168 * @param integer DB-Link
169 *
170 * @return integer Returns -1 always
171 */
172 function command_error_num($link)
173 {
174 return -1;
175 }
176
177 // ###################################################################
178 /**
179 * Overload: insert_id
180 *
181 * @access public
182 *
183 * @param integer Result
184 * @param string PostgreSQL sequence
185 *
186 * @return integer Insert ID
187 */
188 function insert_id($result, $sequence)
189 {
190 $temp = $this->query("SELECT currval($sequence) AS auto_inc");
191 //$temp = call_user_func($this->commands['query'], "SELECT currval($table_col)");
192 var_dump( $temp);
193 print_r($this->fetch_array($temp));
194 }
195 }
196
197 /*=====================================================================*\
198 || ###################################################################
199 || # $HeadURL$
200 || # $Id$
201 || ###################################################################
202 \*=====================================================================*/
203 ?>