Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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_odbc.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 8.42 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\db\driver;
 015   
 016  /**
 017  * Unified ODBC functions
 018  * Unified ODBC functions support any database having ODBC driver, for example Adabas D, IBM DB2, iODBC, Solid, Sybase SQL Anywhere...
 019  * Here we only support MSSQL Server 2000+ because of the provided schema
 020  *
 021  * @note number of bytes returned for returning data depends on odbc.defaultlrl php.ini setting.
 022  * If it is limited to 4K for example only 4K of data is returned max, resulting in incomplete theme data for example.
 023  * @note odbc.defaultbinmode may affect UTF8 characters
 024  */
 025  class mssql_odbc extends \phpbb\db\driver\mssql_base
 026  {
 027      var $last_query_text = '';
 028      var $connect_error = '';
 029   
 030      /**
 031      * {@inheritDoc}
 032      */
 033      function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
 034      {
 035          $this->persistency = $persistency;
 036          $this->user = $sqluser;
 037          $this->dbname = $database;
 038   
 039          $port_delimiter = (defined('PHP_OS') && substr(PHP_OS, 0, 3) === 'WIN') ? ',' : ':';
 040          $this->server = $sqlserver . (($port) ? $port_delimiter . $port : '');
 041   
 042          $max_size = @ini_get('odbc.defaultlrl');
 043          if (!empty($max_size))
 044          {
 045              $unit = strtolower(substr($max_size, -1, 1));
 046              $max_size = (int) $max_size;
 047   
 048              if ($unit == 'k')
 049              {
 050                  $max_size = floor($max_size / 1024);
 051              }
 052              else if ($unit == 'g')
 053              {
 054                  $max_size *= 1024;
 055              }
 056              else if (is_numeric($unit))
 057              {
 058                  $max_size = floor((int) ($max_size . $unit) / 1048576);
 059              }
 060              $max_size = max(8, $max_size) . 'M';
 061   
 062              @ini_set('odbc.defaultlrl', $max_size);
 063          }
 064   
 065          if ($this->persistency)
 066          {
 067              if (!function_exists('odbc_pconnect'))
 068              {
 069                  $this->connect_error = 'odbc_pconnect function does not exist, is odbc extension installed?';
 070                  return $this->sql_error('');
 071              }
 072              $this->db_connect_id = @odbc_pconnect($this->server, $this->user, $sqlpassword);
 073          }
 074          else
 075          {
 076              if (!function_exists('odbc_connect'))
 077              {
 078                  $this->connect_error = 'odbc_connect function does not exist, is odbc extension installed?';
 079                  return $this->sql_error('');
 080              }
 081              $this->db_connect_id = @odbc_connect($this->server, $this->user, $sqlpassword);
 082          }
 083   
 084          return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
 085      }
 086   
 087      /**
 088      * {@inheritDoc}
 089      */
 090      function sql_server_info($raw = false, $use_cache = true)
 091      {
 092          global $cache;
 093   
 094          if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mssqlodbc_version')) === false)
 095          {
 096              $result_id = @odbc_exec($this->db_connect_id, "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')");
 097   
 098              $row = false;
 099              if ($result_id)
 100              {
 101                  $row = odbc_fetch_array($result_id);
 102                  odbc_free_result($result_id);
 103              }
 104   
 105              $this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0;
 106   
 107              if (!empty($cache) && $use_cache)
 108              {
 109                  $cache->put('mssqlodbc_version', $this->sql_server_version);
 110              }
 111          }
 112   
 113          if ($raw)
 114          {
 115              return $this->sql_server_version;
 116          }
 117   
 118          return ($this->sql_server_version) ? 'MSSQL (ODBC)<br />' . $this->sql_server_version : 'MSSQL (ODBC)';
 119      }
 120   
 121      /**
 122      * SQL Transaction
 123      * @access private
 124      */
 125      function _sql_transaction($status = 'begin')
 126      {
 127          switch ($status)
 128          {
 129              case 'begin':
 130                  return @odbc_exec($this->db_connect_id, 'BEGIN TRANSACTION');
 131              break;
 132   
 133              case 'commit':
 134                  return @odbc_exec($this->db_connect_id, 'COMMIT TRANSACTION');
 135              break;
 136   
 137              case 'rollback':
 138                  return @odbc_exec($this->db_connect_id, 'ROLLBACK TRANSACTION');
 139              break;
 140          }
 141   
 142          return true;
 143      }
 144   
 145      /**
 146      * {@inheritDoc}
 147      */
 148      function sql_query($query = '', $cache_ttl = 0)
 149      {
 150          if ($query != '')
 151          {
 152              global $cache;
 153   
 154              if ($this->debug_sql_explain)
 155              {
 156                  $this->sql_report('start', $query);
 157              }
 158              else if ($this->debug_load_time)
 159              {
 160                  $this->curtime = microtime(true);
 161              }
 162   
 163              $this->last_query_text = $query;
 164              $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
 165              $this->sql_add_num_queries($this->query_result);
 166   
 167              if ($this->query_result === false)
 168              {
 169                  try
 170                  {
 171                      $this->query_result = @odbc_exec($this->db_connect_id, $query);
 172                  }
 173                  catch (\Error $e)
 174                  {
 175                      // Do nothing as SQL driver will report the error
 176                  }
 177   
 178                  if ($this->query_result === false)
 179                  {
 180                      $this->sql_error($query);
 181                  }
 182   
 183                  if ($this->debug_sql_explain)
 184                  {
 185                      $this->sql_report('stop', $query);
 186                  }
 187                  else if ($this->debug_load_time)
 188                  {
 189                      $this->sql_time += microtime(true) - $this->curtime;
 190                  }
 191   
 192                  if (!$this->query_result)
 193                  {
 194                      return false;
 195                  }
 196   
 197                  $safe_query_id = $this->clean_query_id($this->query_result);
 198   
 199                  if ($cache && $cache_ttl)
 200                  {
 201                      $this->open_queries[$safe_query_id] = $this->query_result;
 202                      $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
 203                  }
 204                  else if (strpos($query, 'SELECT') === 0)
 205                  {
 206                      $this->open_queries[$safe_query_id] = $this->query_result;
 207                  }
 208              }
 209              else if ($this->debug_sql_explain)
 210              {
 211                  $this->sql_report('fromcache', $query);
 212              }
 213          }
 214          else
 215          {
 216              return false;
 217          }
 218   
 219          return $this->query_result;
 220      }
 221   
 222      /**
 223      * Build LIMIT query
 224      */
 225      function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
 226      {
 227          $this->query_result = false;
 228   
 229          // Since TOP is only returning a set number of rows we won't need it if total is set to 0 (return all rows)
 230          if ($total)
 231          {
 232              // We need to grab the total number of rows + the offset number of rows to get the correct result
 233              if (strpos($query, 'SELECT DISTINCT') === 0)
 234              {
 235                  $query = 'SELECT DISTINCT TOP ' . ($total + $offset) . ' ' . substr($query, 15);
 236              }
 237              else
 238              {
 239                  $query = 'SELECT TOP ' . ($total + $offset) . ' ' . substr($query, 6);
 240              }
 241          }
 242   
 243          $result = $this->sql_query($query, $cache_ttl);
 244   
 245          // Seek by $offset rows
 246          if ($offset)
 247          {
 248              $this->sql_rowseek($offset, $result);
 249          }
 250   
 251          return $result;
 252      }
 253   
 254      /**
 255      * {@inheritDoc}
 256      */
 257      function sql_affectedrows()
 258      {
 259          return ($this->db_connect_id) ? @odbc_num_rows($this->query_result) : false;
 260      }
 261   
 262      /**
 263      * {@inheritDoc}
 264      */
 265      function sql_fetchrow($query_id = false)
 266      {
 267          global $cache;
 268   
 269          if ($query_id === false)
 270          {
 271              $query_id = $this->query_result;
 272          }
 273   
 274          $safe_query_id = $this->clean_query_id($query_id);
 275          if ($cache && $cache->sql_exists($safe_query_id))
 276          {
 277              return $cache->sql_fetchrow($safe_query_id);
 278          }
 279   
 280          return ($query_id) ? odbc_fetch_array($query_id) : false;
 281      }
 282   
 283      /**
 284       * {@inheritdoc}
 285       */
 286      public function sql_last_inserted_id()
 287      {
 288          $result_id = @odbc_exec($this->db_connect_id, 'SELECT @@IDENTITY');
 289   
 290          if ($result_id)
 291          {
 292              if (odbc_fetch_array($result_id))
 293              {
 294                  $id = odbc_result($result_id, 1);
 295                  odbc_free_result($result_id);
 296                  return $id;
 297              }
 298              odbc_free_result($result_id);
 299          }
 300   
 301          return false;
 302      }
 303   
 304      /**
 305      * {@inheritDoc}
 306      */
 307      function sql_freeresult($query_id = false)
 308      {
 309          global $cache;
 310   
 311          if ($query_id === false)
 312          {
 313              $query_id = $this->query_result;
 314          }
 315   
 316          $safe_query_id = $this->clean_query_id($query_id);
 317          if ($cache && $cache->sql_exists($safe_query_id))
 318          {
 319              return $cache->sql_freeresult($safe_query_id);
 320          }
 321   
 322          if (isset($this->open_queries[$safe_query_id]))
 323          {
 324              unset($this->open_queries[$safe_query_id]);
 325              return odbc_free_result($query_id);
 326          }
 327   
 328          return false;
 329      }
 330   
 331      /**
 332      * return sql error array
 333      * @access private
 334      */
 335      function _sql_error()
 336      {
 337          if (function_exists('odbc_errormsg'))
 338          {
 339              $error = array(
 340                  'message'    => @odbc_errormsg(),
 341                  'code'        => @odbc_error(),
 342              );
 343          }
 344          else
 345          {
 346              $error = array(
 347                  'message'    => $this->connect_error,
 348                  'code'        => '',
 349              );
 350          }
 351   
 352          return $error;
 353      }
 354   
 355      /**
 356      * Close sql connection
 357      * @access private
 358      */
 359      function _sql_close()
 360      {
 361          return @odbc_close($this->db_connect_id);
 362      }
 363   
 364      /**
 365      * Build db-specific report
 366      * @access private
 367      */
 368      function _sql_report($mode, $query = '')
 369      {
 370          switch ($mode)
 371          {
 372              case 'start':
 373              break;
 374   
 375              case 'fromcache':
 376                  $endtime = explode(' ', microtime());
 377                  $endtime = $endtime[0] + $endtime[1];
 378   
 379                  $result = @odbc_exec($this->db_connect_id, $query);
 380                  if ($result)
 381                  {
 382                      while ($void = odbc_fetch_array($result))
 383                      {
 384                          // Take the time spent on parsing rows into account
 385                      }
 386                      odbc_free_result($result);
 387                  }
 388   
 389                  $splittime = explode(' ', microtime());
 390                  $splittime = $splittime[0] + $splittime[1];
 391   
 392                  $this->sql_report('record_fromcache', $query, $endtime, $splittime);
 393   
 394              break;
 395          }
 396      }
 397  }
 398