Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpostgresqldb.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezpostgresqldb.php 9173 2002-02-07 11:23:42Z bf $
5 //
6 // Definition of eZPostgreSQLLDB class
7 //
8 // Created on: <19-Jun-2001 16:09:31 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
35 class eZPostgreSQLDB
36 {
37 function __construct( $server, $db, $user, $password )
38 {
39 $this->INI = eZINI::instance( "site.ini" );
40 if ( $this->INI->->variable( "site", "DebugOutput" ) == "enabled")
41 {
42 $this->Database = pg_pconnect( "host=$server dbname=$db user=$user password=$password" );
43 if ( !$this->Database )
44 print( "PostgreSQL error: could not connect to database." );
45 }
46 else
47 {
48 $this->Database = @pg_pconnect( "host=$server dbname=$db user=$user password=$password" );
49 }
50 }
51
55 function isA()
56 {
57 return "postgresql";
58 }
59
60 function &query( $sql )
61 {
62 if ( $this->Database )
63 {
64 $result = @pg_exec( $this->Database, $sql );
65
66 if ( !$result )
67 {
68 if ( $this->INI->->variable( "site", "DebugOutput" ) == "enabled" )
69 {
70 print( "PostgreSQL error: error executing query: $sql ".
71 pg_errormessage ( $this->Database ) );
72 }
73 }
74 }
75
76 return $result;
77 }
78
79 function array_query( &$array, $sql, $min = 0, $max = -1, $column = false )
80 {
81 $array = array();
82 return $this->array_query_append( $array, $sql, $min, $max, $column );
83 }
84
85 function array_query_append( &$array, $sql, $min = 0, $max = -1, $column = false )
86 {
87 $limit = -1;
88 $offset = 0;
89 // check for array parameters
90 if ( is_array( $min ) )
91 {
92 $params = $min;
93
94 if ( isset( $params["Limit"] ) and is_numeric( $params["Limit"] ) )
95 {
96 $limit = $params["Limit"];
97 }
98
99 if ( isset( $params["Offset"] ) and is_numeric( $params["Offset"] ) )
100 {
101 $offset = $params["Offset"];
102 }
103
104 }
105
106 if ( $limit != -1 )
107 {
108 $sql .= " LIMIT $limit, $offset";
109 }
110
111 $result =& $this->query( $sql );
112
113 if ( $result == false )
114 {
115 if ( $this->INI->->variable( "site", "DebugOutput" ) == "enabled" )
116 {
117 print( $this->Error );
118 }
119 eZPBLog::writeWarning( $this->Error );
120 return false;
121 }
122
123 $offset = count( $array );
124
125 if ( pg_numrows( $result ) > 0 )
126 {
127 if ( !is_string( $column ) )
128 {
129 for($i = 0; $i < pg_numrows($result); $i++)
130 {
131 $array[$i + $offset] =& pg_fetch_array ( $result, $i );
132 }
133 }
134 else
135 {
136 for($i = 0; $i < pg_numrows($result); $i++)
137 {
138 $tmp_row =& pg_fetch_array ( $result, $i );
139 $array[$i + $offset] =& $tmp_row[$column];
140 }
141 }
142 }
143 }
144
149 function query_single( &$row, $sql, $column = false )
150 {
151 $array = array();
152 $ret = $this->array_query_append( $array, $sql, 1, 1, $column );
153 $row = $array[0];
154 return $ret;
155 }
156
157
161 function lock( $table )
162 {
163 $this->query( "LOCK TABLE $table" );
164 }
165
169 function unlock()
170 {
171 }
172
176 function begin()
177 {
178 $this->query( "BEGIN WORK" );
179 }
180
184 function commit()
185 {
186 $this->query( "COMMIT WORK" );
187 }
188
192 function rollback()
193 {
194 $this->query( "ROLLBACK WORK" );
195 }
196
202 function nextID( $table, $field="ID" )
203 {
204 $result = @pg_exec( $this->Database, "SELECT $field FROM $table Order BY $field DESC LIMIT 1" );
205
206 $id = 1;
207 if ( $result )
208 {
209 if ( !pg_numrows( $result ) == 0 )
210 {
211 $array = pg_fetch_row( $result, 0 );
212 $id = $array[0];
213 $id++;
214 }
215 else
216 $id = 1;
217 }
218
219 return $id;
220 }
221
225 function &escapeString( $str )
226 {
227 $str = str_replace ("'", "\'", $str );
228 $str = str_replace ("\"", "\\\"", $str );
229 return $str;
230 }
231
236 function &fieldName( $str )
237 {
238 return strToLower( $str );
239 }
240
244 function close()
245 {
246 @pg_close();
247 }
248
250 var $Database;
251 var $INI;
252 }
253
254
255
256 ?>
$i
$i
Definition: admin/adlist.php:91
eZPBLog\writeWarning
static writeWarning( $warning)
Definition: ezpblog.php:177
eZPostgreSQLDB
Definition: ezpostgresqldb.php:36
eZPostgreSQLDB\begin
begin()
Definition: ezpostgresqldb.php:176
eZPostgreSQLDB\rollback
rollback()
Definition: ezpostgresqldb.php:192
eZPostgreSQLDB\escapeString
& escapeString( $str)
Definition: ezpostgresqldb.php:225
eZPostgreSQLDB\__construct
__construct( $server, $db, $user, $password)
Definition: ezpostgresqldb.php:37
eZPostgreSQLDB\isA
isA()
Definition: ezpostgresqldb.php:55
eZPostgreSQLDB\$Database
$Database
database connection
Definition: ezpostgresqldb.php:250
eZPostgreSQLDB\unlock
unlock()
Definition: ezpostgresqldb.php:169
eZPostgreSQLDB\fieldName
& fieldName( $str)
Definition: ezpostgresqldb.php:236
eZPostgreSQLDB\nextID
nextID( $table, $field="ID")
Definition: ezpostgresqldb.php:202
eZPostgreSQLDB\lock
lock( $table)
Definition: ezpostgresqldb.php:161
eZPostgreSQLDB\array_query_append
array_query_append(&$array, $sql, $min=0, $max=-1, $column=false)
Definition: ezpostgresqldb.php:85
eZPostgreSQLDB\query
& query( $sql)
Definition: ezpostgresqldb.php:60
eZPostgreSQLDB\array_query
array_query(&$array, $sql, $min=0, $max=-1, $column=false)
Definition: ezpostgresqldb.php:79
eZPostgreSQLDB\close
close()
Definition: ezpostgresqldb.php:244
eZPostgreSQLDB\commit
commit()
Definition: ezpostgresqldb.php:184
eZPostgreSQLDB\$INI
$INI
Definition: ezpostgresqldb.php:251
eZPostgreSQLDB\query_single
query_single(&$row, $sql, $column=false)
Definition: ezpostgresqldb.php:149
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$str
$str
Definition: ezarticle/modules/content.php:30
$db
$db
Definition: ezarticle/user/authorlist.php:53
$server
$server
Definition: ezarticle/xmlrpc/xmlrpcserver.php:63
$row
$row
Definition: ezcalendar/user/dayview.php:403
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$offset
$offset
Definition: ezstats/admin/cron.php:51
$field
$field
Definition: listtable.php:41
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.