Adding pgsql layer
[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 */
49 var $commands = array(
50 'pconnect' => '$this->command_pg_pconnect',
51 'connect' => '$this->command_pg_connect',
52 'query' => 'pg_query',
53 'error_num' => '$this->command_error_num',
54 'error_str' => '$this->command_error_str',
55 'escape_string' => '$this->command_pg_escape_string',
56 'fetch_assoc' => 'pg_fetch_assoc',
57 'fetch_object' => 'pg_fetch_object',
58 'free_result' => 'pg_free_result',
59 'insert_id' => '%link', // how do we support this...?
60 'num_rows' => 'pg_num_rows',
61 'affected_rows' => 'pg_affected_rows'
62 );
63
64 /**
65 * Port number to connect to
66 * @var integer
67 */
68 var $port = 5432;
69
70 // ###################################################################
71 /**
72 * Constructor
73 */
74 function __construct(&$registry)
75 {
76 parent::__construct($registry);
77 }
78
79 // ###################################################################
80 /**
81 * (PHP 4) Constructor
82 */
83 function DB_PostgreSQL(&$registry)
84 {
85 $this->__construct($registry);
86 }
87
88 // ###################################################################
89 /**
90 * Wrapper: pg_connect
91 *
92 * @access protected
93 *
94 * @param string Server name
95 * @param string User name
96 * @param string Password
97 * @param string Database
98 *
99 * @return integer DB-Link
100 */
101 function command_pg_connect($server, $user, $password, $database)
102 {
103 return pg_connect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
104 }
105
106 // ###################################################################
107 /**
108 * Wrapper: pg_pconnect
109 *
110 * @access protected
111 *
112 * @param string Server name
113 * @param string User name
114 * @param string Password
115 * @param string Database
116 *
117 * @return integer DB-Link
118 */
119 function command_pg_pconnect($server, $user, $password, $database)
120 {
121 return pg_pconnect("host='$server' port={$this->port} user='$user' password='$password' dbname='$database'");
122 }
123
124 // ###################################################################
125 /**
126 * Wrapper: pg_escape_string
127 *
128 * @access protected
129 *
130 * @param integer DB-Link (unused)
131 * @param string Raw string
132 *
133 * @return string Escaped string
134 */
135 function command_pg_escape_string($link, $string)
136 {
137 return pg_escape_string($string);
138 }
139
140 // ###################################################################
141 /**
142 * Wrapper/no support: error string
143 *
144 * @access protected
145 *
146 * @param integer DB-Link
147 *
148 * @return string Error string
149 */
150 function command_error_str($link)
151 {
152 if ($this->result)
153 {
154 return pg_result_error($this->result);
155 }
156
157 return pg_last_error($link);
158 }
159
160 // ###################################################################
161 /**
162 * Not supported: error numbers
163 *
164 * @access protected
165 *
166 * @param integer DB-Link
167 *
168 * @return integer Returns -1 always
169 */
170 function command_error_num($link)
171 {
172 return -1;
173 }
174 }
175
176 /*=====================================================================*\
177 || ###################################################################
178 || # $HeadURL$
179 || # $Id$
180 || ###################################################################
181 \*=====================================================================*/
182 ?>