Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezinformixdb.php
Go to the documentation of this file.
1 <?
3 //
4 // $Id: ezinformixdb.php 6200 2001-07-19 11:33:57Z jakobn $
5 //
6 // Definition of eZInformixDB class
7 //
8 // Created on: <29-Jun-2001 13:17:19 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
37 class eZInformixDB
38 {
42 function __construct( $server, $db, $user, $password )
43 {
44 putenv('INFORMIXSERVER=localhost');
45 putenv('INFORMIXDIR=/opt/informix');
46 ifx_textasvarchar(1);
47 $BlobIDArray = false;
48 $this->Database = ifx_pconnect( "$db@$server", "$user", "$password" );
49 }
50
54 function isA()
55 {
56 return "informix";
57 }
58
64 function setBlobArray( $array )
65 {
66 $this->BlobIDArray = $array;
67 }
68
72 function query( $sql, $print=false )
73 {
74 if ( is_array( $this->BlobIDArray ) )
75 {
76 $result = ifx_query( $sql, $this->Database, $this->BlobIDArray );
77 $this->BlobIDArray = false;
78 }
79 else
80 $result = ifx_query( $sql, $this->Database );
81
82 if ( $print )
83 {
84 print( $sql . "<br>");
85 }
86
87 if ( $result )
88 {
89 return $result;
90 }
91 else
92 {
93 $this->Error = "<code>" . htmlentities( $sql ) . "</code>". ifx_error() . " " . ifx_errormsg() . "<br>\n" ;
94
95 if ( $GLOBALS["DEBUG"] )
96 {
97 print( $this->Error );
98 // exit();
99 }
100 return false;
101 }
102 }
103
104
108 function array_query( &$ret_array, $query, $min=0, $max=-1 )
109 {
110 $limit = -1;
111 $offset = 0;
112 // check for array parameters
113 if ( is_array( $min ) )
114 {
115 $params = $min;
116
117 if ( is_numeric( $params["Limit"] ) )
118 {
119 $limit = $params["Limit"];
120 }
121
122 if ( is_numeric( $params["Offset"] ) )
123 {
124 $offset = $params["Offset"];
125 }
126
127 }
128
129 $ret_array = array();
130 if ( $offset != 0 )
131 $res_id = ifx_prepare( $query, $this->Database, IFX_SCROLL );
132 else
133 $res_id = ifx_prepare( $query, $this->Database );
134
135 if ( !$res_id )
136 {
137 print( "Informix error:" . ifx_errormsg( ) );
138 }
139
140 $rowcount = ifx_affected_rows( $res_id );
141
142 /*
143 if ( $rowcount > 5000 )
144 {
145 printf ("Too many rows in result set (%d)\n<br>", $rowcount );
146 die( "Please restrict your query<br>\n" );
147 }
148 */
149
150 if ( !ifx_do( $res_id ) )
151 {
152 }
153
154
155 if ( $offset != 0 )
156 {
157 $row = ifx_fetch_row( $res_id, (int)$offset + 1 );
158 }
159 else
160 $row = ifx_fetch_row( $res_id, "NEXT" );
161
162 $i=0;
163 while ( is_array( $row ) )
164 {
165 $ret_array[] = $row;
166 $row = ifx_fetch_row( $res_id, "NEXT" );
167
168 $i++;
169 if ( $limit != -1 )
170 {
171 if ( $i >= $limit )
172 break;
173 }
174 }
175 ifx_free_result( $res_id );
176
177 return $ret_array;
178 }
179
184 function query_single( &$row, $sql, $column = false )
185 {
186 $ret = $this->array_query( $array, $sql, 1, 1, $column );
187 $row = $array[0];
188 return $ret;
189 }
190
191
195 function lock( $table )
196 {
197 $this->query( "LOCK TABLE $table IN SHARE MODE" );
198 }
199
203 function unlock()
204 {
205 // no unlock code necessary?
206 // $this->query( "" );
207 }
208
212 function begin()
213 {
214 $this->query( "BEGIN WORK" );
215 }
216
220 function commit()
221 {
222 $this->query( "COMMIT WORK" );
223 }
224
228 function rollback()
229 {
230 $this->query( "ROLLBACK WORK" );
231 }
232
238 function nextID( $table, $field="ID" )
239 {
240 $this->array_query( $res_array, "SELECT $field FROM $table Order BY $field DESC" );
241
242 $id = 1;
243 if ( $res_array )
244 {
245 if ( !count( $res_array ) == 0 )
246 {
247 $id = $res_array[0][$this->fieldName( "id" )];
248 $id++;
249 }
250 else
251 $id = 1;
252 }
253
254 return $id;
255 }
256
260 function &escapeString( $str )
261 {
262 $str = str_replace ("'", "''", $str );
263 $str = str_replace ("\r", "", $str );
264 return $str;
265 }
266
271 function &fieldName( $str )
272 {
273 return strToLower( $str );
274 }
275
279 function close()
280 {
281 ifx_close( $this->Database );
282 }
283
285 var $Database;
286
288 var $BlobIDArray;
289
290 }
291
292 ?>
$i
$i
Definition: admin/adlist.php:91
eZInformixDB
Definition: ezinformixdb.php:38
eZInformixDB\array_query
array_query(&$ret_array, $query, $min=0, $max=-1)
Definition: ezinformixdb.php:108
eZInformixDB\commit
commit()
Definition: ezinformixdb.php:220
eZInformixDB\__construct
__construct( $server, $db, $user, $password)
Definition: ezinformixdb.php:42
eZInformixDB\rollback
rollback()
Definition: ezinformixdb.php:228
eZInformixDB\query_single
query_single(&$row, $sql, $column=false)
Definition: ezinformixdb.php:184
eZInformixDB\fieldName
& fieldName( $str)
Definition: ezinformixdb.php:271
eZInformixDB\unlock
unlock()
Definition: ezinformixdb.php:203
eZInformixDB\nextID
nextID( $table, $field="ID")
Definition: ezinformixdb.php:238
eZInformixDB\query
query( $sql, $print=false)
Definition: ezinformixdb.php:72
eZInformixDB\isA
isA()
Definition: ezinformixdb.php:54
eZInformixDB\setBlobArray
setBlobArray( $array)
Definition: ezinformixdb.php:64
eZInformixDB\begin
begin()
Definition: ezinformixdb.php:212
eZInformixDB\$BlobIDArray
$BlobIDArray
variable for blob ID array
Definition: ezinformixdb.php:288
eZInformixDB\lock
lock( $table)
Definition: ezinformixdb.php:195
eZInformixDB\escapeString
& escapeString( $str)
Definition: ezinformixdb.php:260
eZInformixDB\$Database
$Database
database connection
Definition: ezinformixdb.php:285
eZInformixDB\close
close()
Definition: ezinformixdb.php:279
$result
$result
Definition: companysearch.php:94
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$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+.