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

db2.php

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


 001  <?php
 002  /***************************************************************************
 003   *                                 db2.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","db2");
 026   
 027  class sql_db
 028  {
 029   
 030      var $db_connect_id;
 031      var $query_result;
 032      var $query_resultset;
 033      var $query_numrows;
 034      var $next_id;
 035      var $row = array();
 036      var $rowset = array();
 037      var $row_index;
 038      var $num_queries = 0;
 039   
 040      //
 041      // Constructor
 042      //
 043      function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true)
 044      {
 045          $this->persistency = $persistency;
 046          $this->user = $sqluser;
 047          $this->password = $sqlpassword;
 048          $this->dbname = $database;
 049   
 050          $this->server = $sqlserver;
 051   
 052          if($this->persistency)
 053          {
 054              $this->db_connect_id = odbc_pconnect($this->server, "", "");
 055          }
 056          else
 057          {
 058              $this->db_connect_id = odbc_connect($this->server, "", "");
 059          }
 060   
 061          if($this->db_connect_id)
 062          {
 063              @odbc_autocommit($this->db_connect_id, off);
 064   
 065              return $this->db_connect_id;
 066          }
 067          else
 068          {
 069              return false;
 070          }
 071      }
 072      //
 073      // Other base methods
 074      //
 075      function sql_close()
 076      {
 077          if($this->db_connect_id)
 078          {
 079              if($this->query_result)
 080              {
 081                  @odbc_free_result($this->query_result);
 082              }
 083              $result = @odbc_close($this->db_connect_id);
 084              return $result;
 085          }
 086          else
 087          {
 088              return false;
 089          }
 090      }
 091   
 092   
 093      //
 094      // Query method
 095      //
 096      function sql_query($query = "", $transaction = FALSE)
 097      {
 098          //
 099          // Remove any pre-existing queries
 100          //
 101          unset($this->query_result);
 102          unset($this->row);
 103          if($query != "")
 104          {
 105              $this->num_queries++;
 106   
 107              if(!eregi("^INSERT ",$query))
 108              {
 109                  if(eregi("LIMIT", $query))
 110                  {
 111                      preg_match("/^(.*)LIMIT ([0-9]+)[, ]*([0-9]+)*/s", $query, $limits);
 112   
 113                      $query = $limits[1];
 114                      if($limits[3])
 115                      {
 116                          $row_offset = $limits[2];
 117                          $num_rows = $limits[3];
 118                      }
 119                      else
 120                      {
 121                          $row_offset = 0;
 122                          $num_rows = $limits[2];
 123                      }
 124   
 125                      $query .= " FETCH FIRST ".($row_offset+$num_rows)." ROWS ONLY OPTIMIZE FOR ".($row_offset+$num_rows)." ROWS";
 126   
 127                      $this->query_result = odbc_exec($this->db_connect_id, $query);
 128   
 129                      $query_limit_offset = $row_offset;
 130                      $this->result_numrows[$this->query_result] = $num_rows;
 131                  }
 132                  else
 133                  {
 134                      $this->query_result = odbc_exec($this->db_connect_id, $query);
 135   
 136                      $row_offset = 0;
 137                      $this->result_numrows[$this->query_result] = 5E6;
 138                  }
 139   
 140                  $result_id = $this->query_result;
 141                  if($this->query_result && eregi("^SELECT", $query))
 142                  {
 143   
 144                      for($i = 1; $i < odbc_num_fields($result_id)+1; $i++)
 145                      {
 146                          $this->result_field_names[$result_id][] = odbc_field_name($result_id, $i);
 147                      }
 148   
 149                      $i =  $row_offset + 1;
 150                      $k = 0;
 151                      while(odbc_fetch_row($result_id, $i) && $k < $this->result_numrows[$result_id])
 152                      {
 153   
 154                          for($j = 1; $j < count($this->result_field_names[$result_id])+1; $j++)
 155                          {
 156                              $this->result_rowset[$result_id][$k][$this->result_field_names[$result_id][$j-1]] = odbc_result($result_id, $j);
 157                          }
 158                          $i++;
 159                          $k++;
 160                      }
 161   
 162                      $this->result_numrows[$result_id] = $k;
 163                      $this->row_index[$result_id] = 0;
 164                  }
 165                  else
 166                  {
 167                      $this->result_numrows[$result_id] = @odbc_num_rows($result_id);
 168                      $this->row_index[$result_id] = 0;
 169                  }
 170              }
 171              else
 172              {
 173                  if(eregi("^(INSERT|UPDATE) ", $query))
 174                  {
 175                      $query = preg_replace("/\\\'/s", "''", $query);
 176                  }
 177   
 178                  $this->query_result = odbc_exec($this->db_connect_id, $query);
 179   
 180                  if($this->query_result)
 181                  {
 182                      $sql_id = "VALUES(IDENTITY_VAL_LOCAL())";
 183   
 184                      $id_result = odbc_exec($this->db_connect_id, $sql_id);
 185                      if($id_result)
 186                      {
 187                          $row_result = odbc_fetch_row($id_result);
 188                          if($row_result)
 189                          {
 190                              $this->next_id[$this->query_result] = odbc_result($id_result, 1);
 191                          }
 192                      }
 193                  }
 194   
 195                  odbc_commit($this->db_connect_id);
 196   
 197                  $this->query_limit_offset[$this->query_result] = 0;
 198                  $this->result_numrows[$this->query_result] = 0;
 199              }
 200   
 201              return $this->query_result;
 202          }
 203          else
 204          {
 205              return false;
 206          }
 207      }
 208   
 209      //
 210      // Other query methods
 211      //
 212      function sql_numrows($query_id = 0)
 213      {
 214          if(!$query_id)
 215          {
 216              $query_id = $this->query_result;
 217          }
 218          if($query_id)
 219          {
 220              return $this->result_numrows[$query_id];
 221          }
 222          else
 223          {
 224              return false;
 225          }
 226      }
 227      function sql_affectedrows($query_id = 0)
 228      {
 229          if(!$query_id)
 230          {
 231              $query_id = $this->query_result;
 232          }
 233          if($query_id)
 234          {
 235              return $this->result_numrows[$query_id];
 236          }
 237          else
 238          {
 239              return false;
 240          }
 241      }
 242      function sql_numfields($query_id = 0)
 243      {
 244          if(!$query_id)
 245          {
 246              $query_id = $this->query_result;
 247          }
 248          if($query_id)
 249          {
 250              $result = count($this->result_field_names[$query_id]);
 251              return $result;
 252          }
 253          else
 254          {
 255              return false;
 256          }
 257      }
 258      function sql_fieldname($offset, $query_id = 0)
 259      {
 260          if(!$query_id)
 261          {
 262              $query_id = $this->query_result;
 263          }
 264          if($query_id)
 265          {
 266              $result = $this->result_field_names[$query_id][$offset];
 267              return $result;
 268          }
 269          else
 270          {
 271              return false;
 272          }
 273      }
 274      function sql_fieldtype($offset, $query_id = 0)
 275      {
 276          if(!$query_id)
 277          {
 278              $query_id = $this->query_result;
 279          }
 280          if($query_id)
 281          {
 282              $result = @odbc_field_type($query_id, $offset);
 283              return $result;
 284          }
 285          else
 286          {
 287              return false;
 288          }
 289      }
 290      function sql_fetchrow($query_id = 0)
 291      {
 292          if(!$query_id)
 293          {
 294              $query_id = $this->query_result;
 295          }
 296          if($query_id)
 297          {
 298              if($this->row_index[$query_id] < $this->result_numrows[$query_id])
 299              {
 300                  $result = $this->result_rowset[$query_id][$this->row_index[$query_id]];
 301                  $this->row_index[$query_id]++;
 302                  return $result;
 303              }
 304              else
 305              {
 306                  return false;
 307              }
 308          }
 309          else
 310          {
 311              return false;
 312          }
 313      }
 314      function sql_fetchrowset($query_id = 0)
 315      {
 316          if(!$query_id)
 317          {
 318              $query_id = $this->query_result;
 319          }
 320          if($query_id)
 321          {
 322              $this->row_index[$query_id] = $this->result_numrows[$query_id];
 323              return $this->result_rowset[$query_id];
 324          }
 325          else
 326          {
 327              return false;
 328          }
 329      }
 330      function sql_fetchfield($field, $row = -1, $query_id = 0)
 331      {
 332          if(!$query_id)
 333          {
 334              $query_id = $this->query_result;
 335          }
 336          if($query_id)
 337          {
 338              if($row < $this->result_numrows[$query_id])
 339              {
 340                  if($row == -1)
 341                  {
 342                      $getrow = $this->row_index[$query_id]-1;
 343                  }
 344                  else
 345                  {
 346                      $getrow = $row;
 347                  }
 348   
 349                  return $this->result_rowset[$query_id][$getrow][$this->result_field_names[$query_id][$field]];
 350   
 351              }
 352              else
 353              {
 354                  return false;
 355              }
 356          }
 357          else
 358          {
 359              return false;
 360          }
 361      }
 362      function sql_rowseek($offset, $query_id = 0)
 363      {
 364          if(!$query_id)
 365          {
 366              $query_id = $this->query_result;
 367          }
 368          if($query_id)
 369          {
 370              $this->row_index[$query_id] = 0;
 371              return true;
 372          }
 373          else
 374          {
 375              return false;
 376          }
 377      }
 378      function sql_nextid($query_id = 0)
 379      {
 380          if(!$query_id)
 381          {
 382              $query_id = $this->query_result;
 383          }
 384          if($query_id)
 385          {
 386              return $this->next_id[$query_id];
 387          }
 388          else
 389          {
 390              return false;
 391          }
 392      }
 393      function sql_freeresult($query_id = 0)
 394      {
 395          if(!$query_id)
 396          {
 397              $query_id = $this->query_result;
 398          }
 399          if($query_id)
 400          {
 401              $result = @odbc_free_result($query_id);
 402              return $result;
 403          }
 404          else
 405          {
 406              return false;
 407          }
 408      }
 409      function sql_error($query_id = 0)
 410      {
 411  //        $result['code'] = @odbc_error($this->db_connect_id);
 412  //        $result['message'] = @odbc_errormsg($this->db_connect_id);
 413   
 414          return "";
 415      }
 416   
 417  } // class sql_db
 418   
 419  } // if ... define
 420   
 421  ?>