Verzeichnisstruktur phpBB-2.0.0
- Veröffentlicht
- 03.04.2002
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
mssql-odbc.php
001 <?php
002 /***************************************************************************
003 * mssql-odbc.php
004 * -------------------
005 * begin : Saturday, Feb 13, 2001
006 * copyright : (C) 2001 The phpBB Group
007 * email : support@phpbb.com
008 *
009 * $Id$
010 *
011 ***************************************************************************/
012
013 /***************************************************************************
014 *
015 * This program is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU General Public License as published by
017 * the Free Software Foundation; either version 2 of the License, or
018 * (at your option) any later version.
019 *
020 ***************************************************************************/
021
022 if(!defined("SQL_LAYER"))
023 {
024
025 define("SQL_LAYER","mssql-odbc");
026
027 class sql_db
028 {
029
030 var $db_connect_id;
031 var $result;
032
033 var $next_id;
034
035 var $num_rows = array();
036 var $current_row = array();
037 var $field_names = array();
038 var $field_types = array();
039 var $result_rowset = array();
040
041 var $num_queries = 0;
042
043 //
044 // Constructor
045 //
046 function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
047 {
048 $this->persistency = $persistency;
049 $this->server = $sqlserver;
050 $this->user = $sqluser;
051 $this->password = $sqlpassword;
052 $this->dbname = $database;
053
054 $this->db_connect_id = ($this->persistency) ? odbc_pconnect($this->server, $this->user, $this->password) : odbc_connect($this->server, $this->user, $this->password);
055
056 return ( $this->db_connect_id ) ? $this->db_connect_id : false;
057 }
058 //
059 // Other base methods
060 //
061 function sql_close()
062 {
063 if($this->db_connect_id)
064 {
065 if( $this->in_transaction )
066 {
067 @odbc_commit($this->db_connect_id);
068 }
069
070 if( count($this->result_rowset) )
071 {
072 unset($this->result_rowset);
073 unset($this->field_names);
074 unset($this->field_types);
075 unset($this->num_rows);
076 unset($this->current_row);
077 }
078
079 return @odbc_close($this->db_connect_id);
080 }
081 else
082 {
083 return false;
084 }
085 }
086
087 //
088 // Query method
089 //
090 function sql_query($query = "", $transaction = FALSE)
091 {
092 if( $query != "" )
093 {
094 $this->num_queries++;
095
096 if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
097 {
098 if( !odbc_autocommit($this->db_connect_id, false) )
099 {
100 return false;
101 }
102 $this->in_transaction = TRUE;
103 }
104
105 if( preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits) )
106 {
107 $query = $limits[1];
108
109 if( !empty($limits[2]) )
110 {
111 $row_offset = ( $limits[4] ) ? $limits[3] : "";
112 $num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
113
114 $query = "TOP " . ( $row_offset + $num_rows ) . $query;
115 }
116
117 $this->result = odbc_exec($this->db_connect_id, "SELECT $query");
118
119 if( $this->result )
120 {
121 if( empty($this->field_names[$this->result]) )
122 {
123 for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++)
124 {
125 $this->field_names[$this->result][] = odbc_field_name($this->result, $i);
126 $this->field_types[$this->result][] = odbc_field_type($this->result, $i);
127 }
128 }
129
130 $this->current_row[$this->result] = 0;
131 $this->result_rowset[$this->result] = array();
132
133 $row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1;
134 $row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9;
135 $row_inner = 0;
136
137 while( odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max )
138 {
139 for($j = 0; $j < count($this->field_names[$this->result]); $j++)
140 {
141 $this->result_rowset[$this->result][$row_inner][$this->field_names[$this->result][$j]] = stripslashes(odbc_result($this->result, $j + 1));
142 }
143
144 $row_outer++;
145 $row_inner++;
146 }
147
148 $this->num_rows[$this->result] = count($this->result_rowset[$this->result]);
149 }
150
151 }
152 else if( eregi("^INSERT ", $query) )
153 {
154 $this->result = odbc_exec($this->db_connect_id, $query);
155
156 if( $this->result )
157 {
158 $result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
159 if( $result_id )
160 {
161 if( odbc_fetch_row($result_id) )
162 {
163 $this->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
164 $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
165 }
166 }
167 }
168 }
169 else
170 {
171 $this->result = odbc_exec($this->db_connect_id, $query);
172
173 if( $this->result )
174 {
175 $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
176 }
177 }
178
179 if( !$this->result )
180 {
181 if( $this->in_transaction )
182 {
183 odbc_rollback($this->db_connect_id);
184 odbc_autocommit($this->db_connect_id, true);
185 $this->in_transaction = FALSE;
186 }
187
188 return false;
189 }
190
191 if( $transaction == END_TRANSACTION && $this->in_transaction )
192 {
193 $this->in_transaction = FALSE;
194
195 if ( !odbc_commit($this->db_connect_id) )
196 {
197 odbc_rollback($this->db_connect_id);
198 odbc_autocommit($this->db_connect_id, true);
199 return false;
200 }
201 odbc_autocommit($this->db_connect_id, true);
202 }
203
204 odbc_free_result($this->result);
205
206 return $this->result;
207 }
208 else
209 {
210 if( $transaction == END_TRANSACTION && $this->in_transaction )
211 {
212 $this->in_transaction = FALSE;
213
214 if ( !@odbc_commit($this->db_connect_id) )
215 {
216 odbc_rollback($this->db_connect_id);
217 odbc_autocommit($this->db_connect_id, true);
218 return false;
219 }
220 odbc_autocommit($this->db_connect_id, true);
221 }
222
223 return true;
224 }
225 }
226
227 //
228 // Other query methods
229 //
230 function sql_numrows($query_id = 0)
231 {
232 if( !$query_id )
233 {
234 $query_id = $this->result;
235 }
236
237 return ( $query_id ) ? $this->num_rows[$query_id] : false;
238 }
239
240 function sql_numfields($query_id = 0)
241 {
242 if( !$query_id )
243 {
244 $query_id = $this->result;
245 }
246
247 return ( $query_id ) ? count($this->field_names[$query_id]) : false;
248 }
249
250 function sql_fieldname($offset, $query_id = 0)
251 {
252 if( !$query_id )
253 {
254 $query_id = $this->result;
255 }
256
257 return ( $query_id ) ? $this->field_names[$query_id][$offset] : false;
258 }
259
260 function sql_fieldtype($offset, $query_id = 0)
261 {
262 if( !$query_id )
263 {
264 $query_id = $this->result;
265 }
266
267 return ( $query_id ) ? $this->field_types[$query_id][$offset] : false;
268 }
269
270 function sql_fetchrow($query_id = 0)
271 {
272 if( !$query_id )
273 {
274 $query_id = $this->result;
275 }
276
277 if( $query_id )
278 {
279 return ( $this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false;
280 }
281 else
282 {
283 return false;
284 }
285 }
286
287 function sql_fetchrowset($query_id = 0)
288 {
289 if( !$query_id )
290 {
291 $query_id = $this->result;
292 }
293
294 if( $query_id )
295 {
296 return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false;
297 }
298 else
299 {
300 return false;
301 }
302 }
303
304 function sql_fetchfield($field, $row = -1, $query_id = 0)
305 {
306 if( !$query_id )
307 {
308 $query_id = $this->result;
309 }
310
311 if( $query_id )
312 {
313 if( $row < $this->num_rows[$query_id] )
314 {
315 $getrow = ( $row == -1 ) ? $this->current_row[$query_id] - 1 : $row;
316
317 return $this->result_rowset[$query_id][$getrow][$this->field_names[$query_id][$field]];
318
319 }
320 else
321 {
322 return false;
323 }
324 }
325 else
326 {
327 return false;
328 }
329 }
330
331 function sql_rowseek($offset, $query_id = 0)
332 {
333 if( !$query_id )
334 {
335 $query_id = $this->result;
336 }
337
338 if( $query_id )
339 {
340 $this->current_row[$query_id] = $offset - 1;
341 return true;
342 }
343 else
344 {
345 return false;
346 }
347 }
348
349 function sql_nextid()
350 {
351 return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
352 }
353
354 function sql_affectedrows()
355 {
356 return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false;
357 }
358
359 function sql_freeresult($query_id = 0)
360 {
361 if( !$query_id )
362 {
363 $query_id = $this->result;
364 }
365
366 unset($this->num_rows[$query_id]);
367 unset($this->current_row[$query_id]);
368 unset($this->result_rowset[$query_id]);
369 unset($this->field_names[$query_id]);
370 unset($this->field_types[$query_id]);
371
372 return true;
373 }
374
375 function sql_error()
376 {
377 $error['code'] = odbc_error($this->db_connect_id);
378 $error['message'] = odbc_errormsg($this->db_connect_id);
379
380 return $error;
381 }
382
383 } // class sql_db
384
385 } // if ... define
386
387 ?>