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

postgres7.php

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


001  <?php
002    /***************************************************************************
003     *                               postgres7.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","postgresql");
026   
027  class sql_db
028  {
029   
030      var $db_connect_id;
031      var $query_result;
032      var $in_transaction = 0;
033      var $row = array();
034      var $rowset = array();
035      var $rownum = array();
036      var $num_queries = 0;
037   
038      //
039      // Constructor
040      //
041      function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
042      {
043          $this->connect_string = "";
044   
045          if( $sqluser )
046          {
047              $this->connect_string .= "user=$sqluser ";
048          }
049   
050          if( $sqlpassword )
051          {
052              $this->connect_string .= "password=$sqlpassword ";
053          }
054   
055          if( $sqlserver )
056          {
057              if( ereg(":", $sqlserver) )
058              {
059                  list($sqlserver, $sqlport) = split(":", $sqlserver);
060                  $this->connect_string .= "host=$sqlserver port=$sqlport ";
061              }
062              else
063              {
064                  if( $sqlserver != "localhost" )
065                  {
066                      $this->connect_string .= "host=$sqlserver ";
067                  }
068              }
069          }
070   
071          if( $database )
072          {
073              $this->dbname = $database;
074              $this->connect_string .= "dbname=$database";
075          }
076   
077          $this->persistency = $persistency;
078   
079          $this->db_connect_id = ( $this->persistency ) ? pg_pconnect($this->connect_string) : pg_connect($this->connect_string);
080   
081          return ( $this->db_connect_id ) ? $this->db_connect_id : false;
082      }
083   
084      //
085      // Other base methods
086      //
087      function sql_close()
088      {
089          if( $this->db_connect_id )
090          {
091              //
092              // Commit any remaining transactions
093              //
094              if( $this->in_transaction )
095              {
096                  @pg_exec($this->db_connect_id, "COMMIT");
097              }
098   
099              if( $this->query_result )
100              {
101                  @pg_freeresult($this->query_result);
102              }
103   
104              return @pg_close($this->db_connect_id);
105          }
106          else
107          {
108              return false;
109          }
110      }
111   
112      //
113      // Query method
114      //
115      function sql_query($query = "", $transaction = false)
116      {
117          //
118          // Remove any pre-existing queries
119          //
120          unset($this->query_result);
121          if( $query != "" )
122          {
123              $this->num_queries++;
124   
125              $query = preg_replace("/LIMIT ([0-9]+),([ 0-9]+)/", "LIMIT \\2 OFFSET \\1", $query);
126   
127              if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction )
128              {
129                  $this->in_transaction = TRUE;
130   
131                  if( !@pg_exec($this->db_connect_id, "BEGIN") )
132                  {
133                      return false;
134                  }
135              }
136   
137              $this->query_result = @pg_exec($this->db_connect_id, $query);
138              if( $this->query_result )
139              {
140                  if( $transaction == END_TRANSACTION )
141                  {
142                      $this->in_transaction = FALSE;
143   
144                      if( !@pg_exec($this->db_connect_id, "COMMIT") )
145                      {
146                          @pg_exec($this->db_connect_id, "ROLLBACK");
147                          return false;
148                      }
149                  }
150   
151                  $this->last_query_text[$this->query_result] = $query;
152                  $this->rownum[$this->query_result] = 0;
153   
154                  unset($this->row[$this->query_result]);
155                  unset($this->rowset[$this->query_result]);
156   
157                  return $this->query_result;
158              }
159              else
160              {
161                  if( $this->in_transaction )
162                  {
163                      @pg_exec($this->db_connect_id, "ROLLBACK");
164                  }
165                  $this->in_transaction = FALSE;
166   
167                  return false;
168              }
169          }
170          else
171          {
172              if( $transaction == END_TRANSACTION && $this->in_transaction )
173              {
174                  $this->in_transaction = FALSE;
175   
176                  if( !@pg_exec($this->db_connect_id, "COMMIT") )
177                  {
178                      @pg_exec($this->db_connect_id, "ROLLBACK");
179                      return false;
180                  }
181              }
182   
183              return true;
184          }
185      }
186   
187      //
188      // Other query methods
189      //
190      function sql_numrows($query_id = 0)
191      {
192          if( !$query_id )
193          {
194              $query_id = $this->query_result;
195          }
196   
197          return ( $query_id ) ? @pg_numrows($query_id) : false;
198      }
199   
200      function sql_numfields($query_id = 0)
201      {
202          if( !$query_id )
203          {
204              $query_id = $this->query_result;
205          }
206   
207          return ( $query_id ) ? @pg_numfields($query_id) : false;
208      }
209   
210      function sql_fieldname($offset, $query_id = 0)
211      {
212          if( !$query_id )
213          {
214              $query_id = $this->query_result;
215          }
216   
217          return ( $query_id ) ? @pg_fieldname($query_id, $offset) : false;
218      }
219   
220      function sql_fieldtype($offset, $query_id = 0)
221      {
222          if( !$query_id )
223          {
224              $query_id = $this->query_result;
225          }
226   
227          return ( $query_id ) ? @pg_fieldtype($query_id, $offset) : false;
228      }
229   
230      function sql_fetchrow($query_id = 0)
231      {
232          if( !$query_id )
233          {
234              $query_id = $this->query_result;
235          }
236   
237          if($query_id)
238          {
239              $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]);
240   
241              if( $this->row )
242              {
243                  $this->rownum[$query_id]++;
244                  return $this->row;
245              }
246          }
247   
248          return false;
249      }
250   
251      function sql_fetchrowset($query_id = 0)
252      {
253          if( !$query_id )
254          {
255              $query_id = $this->query_result;
256          }
257   
258          if( $query_id )
259          {
260              unset($this->rowset[$query_id]);
261              unset($this->row[$query_id]);
262              $this->rownum[$query_id] = 0;
263   
264              while( $this->rowset = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC) )
265              {
266                  $result[] = $this->rowset;
267                  $this->rownum[$query_id]++;
268              }
269   
270              return $result;
271          }
272   
273          return false;
274      }
275   
276      function sql_fetchfield($field, $row_offset=-1, $query_id = 0)
277      {
278          if( !$query_id )
279          {
280              $query_id = $this->query_result;
281          }
282   
283          if( $query_id )
284          {
285              if( $row_offset != -1 )
286              {
287                  $this->row = @pg_fetch_array($query_id, $row_offset, PGSQL_ASSOC);
288              }
289              else
290              {
291                  if( $this->rownum[$query_id] )
292                  {
293                      $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id]-1, PGSQL_ASSOC);
294                  }
295                  else
296                  {
297                      $this->row = @pg_fetch_array($query_id, $this->rownum[$query_id], PGSQL_ASSOC);
298   
299                      if( $this->row )
300                      {
301                          $this->rownum[$query_id]++;
302                      }
303                  }
304              }
305   
306              return $this->row[$field];
307          }
308   
309          return false;
310      }
311   
312      function sql_rowseek($offset, $query_id = 0)
313      {
314   
315          if(!$query_id)
316          {
317              $query_id = $this->query_result;
318          }
319   
320          if( $query_id )
321          {
322              if( $offset > -1 )
323              {
324                  $this->rownum[$query_id] = $offset;
325                  return true;
326              }
327              else
328              {
329                  return false;
330              }
331          }
332   
333          return false;
334      }
335   
336      function sql_nextid()
337      {
338          $query_id = $this->query_result;
339   
340          if($query_id && $this->last_query_text[$query_id] != "")
341          {
342              if( preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text[$query_id], $tablename) )
343              {
344                  $query = "SELECT currval('" . $tablename[1] . "_id_seq') AS last_value";
345                  $temp_q_id =  @pg_exec($this->db_connect_id, $query);
346                  if( !$temp_q_id )
347                  {
348                      return false;
349                  }
350   
351                  $temp_result = @pg_fetch_array($temp_q_id, 0, PGSQL_ASSOC);
352   
353                  return ( $temp_result ) ? $temp_result['last_value'] : false;
354              }
355          }
356   
357          return false;
358      }
359   
360      function sql_affectedrows($query_id = 0)
361      {
362          if( !$query_id )
363          {
364              $query_id = $this->query_result;
365          }
366   
367          return ( $query_id ) ? @pg_cmdtuples($query_id) : false;
368      }
369   
370      function sql_freeresult($query_id = 0)
371      {
372          if( !$query_id )
373          {
374              $query_id = $this->query_result;
375          }
376   
377          return ( $query_id ) ? @pg_freeresult($query_id) : false;
378      }
379   
380      function sql_error($query_id = 0)
381      {
382          if( !$query_id )
383          {
384              $query_id = $this->query_result;
385          }
386   
387          $result['message'] = @pg_errormessage($this->db_connect_id);
388          $result['code'] = -1;
389   
390          return $result;
391      }
392   
393  } // class ... db_sql
394   
395  } // if ... defined
396   
397  ?>