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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

mssql.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 8.70 KiB


001  <?php
002  /***************************************************************************
003   *                                 mssql.php
004   *                            -------------------
005   *   begin                : Saturday, Feb 13, 2001
006   *   copyright            : (C) 2001 The phpBB Group
007   *   email                : supportphpbb.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");
026   
027  class sql_db
028  {
029   
030      var $db_connect_id;
031      var $result;
032   
033      var $next_id;
034      var $in_transaction = 0;
035   
036      var $row = array();
037      var $rowset = array();
038      var $limit_offset;
039      var $query_limit_success;
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->user = $sqluser;
050          $this->password = $sqlpassword;
051          $this->server = $sqlserver;
052          $this->dbname = $database;
053   
054          $this->db_connect_id = ( $this->persistency ) ? @mssql_pconnect($this->server, $this->user, $this->password) : @mssql_connect($this->server, $this->user, $this->password);
055   
056          if( $this->db_connect_id && $this->dbname != "" )
057          {
058              if( !mssql_select_db($this->dbname, $this->db_connect_id) )
059              {
060                  mssql_close($this->db_connect_id);
061                  return false;
062              }
063          }
064   
065          return $this->db_connect_id;
066      }
067   
068      //
069      // Other base methods
070      //
071      function sql_close()
072      {
073          if($this->db_connect_id)
074          {
075              //
076              // Commit any remaining transactions
077              //
078              if( $this->in_transaction )
079              {
080                  @mssql_query("COMMIT", $this->db_connect_id);
081              }
082   
083              return @mssql_close($this->db_connect_id);
084          }
085          else
086          {
087              return false;
088          }
089      }
090   
091   
092      //
093      // Query method
094      //
095      function sql_query($query = '', $transaction = FALSE)
096      {
097          //
098          // Remove any pre-existing queries
099          //
100          unset($this->result);
101          unset($this->row);
102   
103          if ( $query != '' )
104          {
105              $this->num_queries++;
106   
107              if ( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
108              {
109                  if ( !@mssql_query('BEGIN TRANSACTION', $this->db_connect_id) )
110                  {
111                      return false;
112                  }
113                  $this->in_transaction = TRUE;
114              }
115   
116              //
117              // Does query contain any LIMIT code? If so pull out relevant start and num_results
118              // This isn't terribly easy with MSSQL, whatever you do will potentially impact
119              // performance compared to an 'in-built' limit
120              //
121              // Another issue is the 'lack' of a returned true value when a query is valid but has
122              // no result set (as with all the other DB interfaces). It seems though that it's
123              // 'fair' to say that if a query returns a false result (ie. no resource id) then the
124              // SQL was valid but had no result set. If the query returns nothing but the rowcount
125              // returns something then there's a problem. This may well be a false assumption though
126              // ... needs checking under Windows itself.
127              //
128              if( preg_match('#^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$#s', $query, $limits) )
129              {
130                  $query = $limits[1];
131   
132                  if( !empty($limits[2]) )
133                  {
134                      $row_offset = ( $limits[4] ) ? $limits[3] : "";
135                      $num_rows = ( $limits[4] ) ? $limits[4] : $limits[3];
136   
137                      $query = 'TOP ' . ( $row_offset + $num_rows ) . $query;
138                  }
139   
140                  $this->result = @mssql_query("SELECT $query", $this->db_connect_id); 
141   
142                  if( $this->result )
143                  {
144                      $this->limit_offset[$this->result] = ( !empty($row_offset) ) ? $row_offset : 0;
145   
146                      if( $row_offset > 0 )
147                      {
148                          @mssql_data_seek($this->result, $row_offset);
149                      }
150                  }
151              }
152              else if( preg_match('#^INSERT #i', $query) )
153              {
154                  if( @mssql_query($query, $this->db_connect_id) )
155                  {
156                      $this->result = time() + microtime();
157   
158                      $result_id = @mssql_query('SELECT @@IDENTITY AS id, @@ROWCOUNT as affected', $this->db_connect_id);
159                      if( $result_id )
160                      {
161                          if( $row = @mssql_fetch_array($result_id) )
162                          {
163                              $this->next_id[$this->db_connect_id] = $row['id'];    
164                              $this->affected_rows[$this->db_connect_id] = $row['affected'];
165                          }
166                      }
167                  }
168              }
169              else
170              {
171                  if( @mssql_query($query, $this->db_connect_id) )
172                  {
173                      $this->result = time() + microtime();
174   
175                      $result_id = @mssql_query('SELECT @@ROWCOUNT as affected', $this->db_connect_id);
176                      if( $result_id )
177                      {
178                          if( $row = @mssql_fetch_array($result_id) )
179                          {
180                              $this->affected_rows[$this->db_connect_id] = $row['affected'];
181                          }
182                      }
183                  }
184              }
185   
186              if( !$this->result )
187              {
188                  if( $this->in_transaction )
189                  {
190                      @mssql_query('ROLLBACK', $this->db_connect_id);
191                      $this->in_transaction = FALSE;
192                  }
193   
194                  return false;
195              }
196   
197              if( $transaction == END_TRANSACTION && $this->in_transaction )
198              {
199                  $this->in_transaction = FALSE;
200   
201                  if( !@mssql_query('COMMIT', $this->db_connect_id) )
202                  {
203                      @mssql_query("ROLLBACK", $this->db_connect_id);
204                      return false;
205                  }
206              }
207   
208              return $this->result;
209          }
210          else
211          {
212              if( $transaction == END_TRANSACTION && $this->in_transaction  )
213              {
214                  $this->in_transaction = FALSE;
215   
216                  if( !@mssql_query('COMMIT', $this->db_connect_id) )
217                  {
218                      @mssql_query('ROLLBACK', $this->db_connect_id);
219                      return false;
220                  }
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          if( $query_id )
238          {
239              return ( !empty($this->limit_offset[$query_id]) ) ? @mssql_num_rows($query_id) - $this->limit_offset[$query_id] : @mssql_num_rows($query_id);
240          }
241          else
242          {
243              return false;
244          }
245      }
246   
247      function sql_numfields($query_id = 0)
248      {
249          if( !$query_id )
250          {
251              $query_id = $this->result;
252          }
253   
254          return ( $query_id ) ? @mssql_num_fields($query_id) : false;
255      }
256   
257      function sql_fieldname($offset, $query_id = 0)
258      {
259          if( !$query_id )
260          {
261              $query_id = $this->result;
262          }
263   
264          return ( $query_id ) ? @mssql_field_name($query_id, $offset) : false;
265      }
266   
267      function sql_fieldtype($offset, $query_id = 0)
268      {
269          if(!$query_id)
270          {
271              $query_id = $this->result;
272          }
273   
274          return ( $query_id ) ? @mssql_field_type($query_id, $offset) : false;
275      }
276   
277      function sql_fetchrow($query_id = 0)
278      {
279          if( !$query_id )
280          {
281              $query_id = $this->result;
282          }
283   
284          if( $query_id )
285          {
286              empty($row);
287   
288              $row = @mssql_fetch_array($query_id);
289   
290              while( list($key, $value) = @each($row) )
291              {
292                  $row[$key] = ($value === ' ') ? '' : stripslashes($value);
293              }
294              @reset($row);
295   
296              return $row;
297          }
298          else
299          {
300              return false;
301          }
302      }
303   
304      function sql_fetchrowset($query_id = 0)
305      {
306          if( !$query_id )
307          {
308              $query_id = $this->result;
309          }
310   
311          if( $query_id )
312          {
313              $i = 0;
314              empty($rowset);
315   
316              while( $row = @mssql_fetch_array($query_id))
317              {
318                  while( list($key, $value) = @each($row) )
319                  {
320                      $rowset[$i][$key] = ($value === ' ') ? '' : stripslashes($value);
321                  }
322                  $i++;
323              }
324              @reset($rowset);
325   
326              return $rowset;
327          }
328          else
329          {
330              return false;
331          }
332      }
333   
334      function sql_fetchfield($field, $row = -1, $query_id)
335      {
336          if( !$query_id )
337          {
338              $query_id = $this->result;
339          }
340   
341          if( $query_id )
342          {
343              if( $row != -1 )
344              {
345                  if( $this->limit_offset[$query_id] > 0 )
346                  {
347                      $result = ( !empty($this->limit_offset[$query_id]) ) ? @mssql_result($this->result, ($this->limit_offset[$query_id] + $row), $field) : false;
348                  }
349                  else
350                  {
351                      $result = @mssql_result($this->result, $row, $field);
352                  }
353              }
354              else
355              {
356                  if( empty($this->row[$query_id]) )
357                  {
358                      $this->row[$query_id] = @mssql_fetch_array($query_id);
359                      $result = ($this->row[$query_id][$field] === ' ') ? '' : stripslashes($this->row[$query_id][$field]);
360                  }
361              }
362   
363              return $result;
364          }
365          else
366          {
367              return false;
368          }
369      }
370   
371      function sql_rowseek($rownum, $query_id = 0)
372      {
373          if( !$query_id )
374          {
375              $query_id = $this->result;
376          }
377   
378          if( $query_id )
379          {
380              return ( !empty($this->limit_offset[$query_id]) ) ? @mssql_data_seek($query_id, ($this->limit_offset[$query_id] + $rownum)) : @mssql_data_seek($query_id, $rownum);
381          }
382          else
383          {
384              return false;
385          }
386      }
387   
388      function sql_nextid()
389      {
390          return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false;
391      }
392   
393      function sql_affectedrows()
394      {
395          return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false;
396      }
397   
398      function sql_freeresult($query_id = 0)
399      {
400          if( !$query_id )
401          {
402              $query_id = $this->result;
403          }
404   
405          return ( $query_id ) ? @mssql_free_result($query_id) : false;
406      }
407   
408      function sql_error($query_id = 0)
409      {
410          $result['message'] = @mssql_get_last_message();
411          return $result;
412      }
413   
414  } // class sql_db
415   
416  } // if ... define
417   
418  ?>