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

mysql_extractor.php

Zuletzt modifiziert: 01.05.2026, 11:25 - Dateigröße: 6.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\extractor;
 015   
 016  use phpbb\db\extractor\exception\extractor_not_initialized_exception;
 017   
 018  class mysql_extractor extends base_extractor
 019  {
 020      /**
 021      * {@inheritdoc}
 022      */
 023      public function write_start($table_prefix)
 024      {
 025          if (!$this->is_initialized)
 026          {
 027              throw new extractor_not_initialized_exception();
 028          }
 029   
 030          $sql_data = "#\n";
 031          $sql_data .= "# phpBB Backup Script\n";
 032          $sql_data .= "# Dump of tables for $table_prefix\n";
 033          $sql_data .= "# DATE : " . gmdate("d-m-Y H:i:s", $this->time) . " GMT\n";
 034          $sql_data .= "#\n";
 035          $this->flush($sql_data);
 036      }
 037   
 038      /**
 039      * {@inheritdoc}
 040      */
 041      public function write_table($table_name)
 042      {
 043          static $new_extract;
 044   
 045          if (!$this->is_initialized)
 046          {
 047              throw new extractor_not_initialized_exception();
 048          }
 049   
 050          if ($new_extract === null)
 051          {
 052              if ($this->db->get_sql_layer() === 'mysqli' || version_compare($this->db->sql_server_info(true), '3.23.20', '>='))
 053              {
 054                  $new_extract = true;
 055              }
 056              else
 057              {
 058                  $new_extract = false;
 059              }
 060          }
 061   
 062          if ($new_extract)
 063          {
 064              $this->new_write_table($table_name);
 065          }
 066          else
 067          {
 068              $this->old_write_table($table_name);
 069          }
 070      }
 071   
 072      /**
 073      * {@inheritdoc}
 074      */
 075      public function write_data($table_name)
 076      {
 077          if (!$this->is_initialized)
 078          {
 079              throw new extractor_not_initialized_exception();
 080          }
 081   
 082          $this->write_data_mysqli($table_name);
 083      }
 084   
 085      /**
 086      * Extracts data from database table (for MySQLi driver)
 087      *
 088      * @param    string    $table_name    name of the database table
 089      * @return null
 090      * @throws extractor_not_initialized_exception when calling this function before init_extractor()
 091      */
 092      protected function write_data_mysqli($table_name)
 093      {
 094          if (!$this->is_initialized)
 095          {
 096              throw new extractor_not_initialized_exception();
 097          }
 098   
 099          $sql = "SELECT *
 100              FROM $table_name";
 101          $result = mysqli_query($this->db->get_db_connect_id(), $sql, MYSQLI_USE_RESULT);
 102          if ($result != false)
 103          {
 104              $fields_cnt = mysqli_num_fields($result);
 105   
 106              // Get field information
 107              $field = mysqli_fetch_fields($result);
 108              $field_set = array();
 109   
 110              for ($j = 0; $j < $fields_cnt; $j++)
 111              {
 112                  $field_set[] = $field[$j]->name;
 113              }
 114   
 115              $search            = array("\\", "'", "\x00", "\x0a", "\x0d", "\x1a", '"');
 116              $replace        = array("\\\\", "\\'", '\0', '\n', '\r', '\Z', '\\"');
 117              $fields            = implode(', ', $field_set);
 118              $sql_data        = 'INSERT INTO ' . $table_name . ' (' . $fields . ') VALUES ';
 119              $first_set        = true;
 120              $query_len        = 0;
 121              $max_len        = get_usable_memory();
 122   
 123              while ($row = mysqli_fetch_row($result))
 124              {
 125                  $values    = array();
 126                  if ($first_set)
 127                  {
 128                      $query = $sql_data . '(';
 129                  }
 130                  else
 131                  {
 132                      $query  .= ',(';
 133                  }
 134   
 135                  for ($j = 0; $j < $fields_cnt; $j++)
 136                  {
 137                      if (!isset($row[$j]) || is_null($row[$j]))
 138                      {
 139                          $values[$j] = 'NULL';
 140                      }
 141                      else if (($field[$j]->flags & 32768) && !($field[$j]->flags & 1024))
 142                      {
 143                          $values[$j] = $row[$j];
 144                      }
 145                      else
 146                      {
 147                          $values[$j] = "'" . str_replace($search, $replace, $row[$j]) . "'";
 148                      }
 149                  }
 150                  $query .= implode(', ', $values) . ')';
 151   
 152                  $query_len += strlen($query);
 153                  if ($query_len > $max_len)
 154                  {
 155                      $this->flush($query . ";\n\n");
 156                      $query = '';
 157                      $query_len = 0;
 158                      $first_set = true;
 159                  }
 160                  else
 161                  {
 162                      $first_set = false;
 163                  }
 164              }
 165              mysqli_free_result($result);
 166   
 167              // check to make sure we have nothing left to flush
 168              if (!$first_set && $query)
 169              {
 170                  $this->flush($query . ";\n\n");
 171              }
 172          }
 173      }
 174   
 175      /**
 176      * Extracts database table structure (for MySQLi or MySQL 3.23.20+)
 177      *
 178      * @param    string    $table_name    name of the database table
 179      * @return null
 180      * @throws extractor_not_initialized_exception when calling this function before init_extractor()
 181      */
 182      protected function new_write_table($table_name)
 183      {
 184          if (!$this->is_initialized)
 185          {
 186              throw new extractor_not_initialized_exception();
 187          }
 188   
 189          $sql = 'SHOW CREATE TABLE ' . $table_name;
 190          $result = $this->db->sql_query($sql);
 191          $row = $this->db->sql_fetchrow($result);
 192   
 193          $sql_data = '# Table: ' . $table_name . "\n";
 194          $sql_data .= "DROP TABLE IF EXISTS $table_name;\n";
 195          $this->flush($sql_data . $row['Create Table'] . ";\n\n");
 196   
 197          $this->db->sql_freeresult($result);
 198      }
 199   
 200      /**
 201      * Extracts database table structure (for MySQL versions older than 3.23.20)
 202      *
 203      * @param    string    $table_name    name of the database table
 204      * @return null
 205      * @throws extractor_not_initialized_exception when calling this function before init_extractor()
 206      */
 207      protected function old_write_table($table_name)
 208      {
 209          if (!$this->is_initialized)
 210          {
 211              throw new extractor_not_initialized_exception();
 212          }
 213   
 214          $sql_data = '# Table: ' . $table_name . "\n";
 215          $sql_data .= "DROP TABLE IF EXISTS $table_name;\n";
 216          $sql_data .= "CREATE TABLE $table_name(\n";
 217          $rows = array();
 218   
 219          $sql = "SHOW FIELDS
 220              FROM $table_name";
 221          $result = $this->db->sql_query($sql);
 222   
 223          while ($row = $this->db->sql_fetchrow($result))
 224          {
 225              $line = '   ' . $row['Field'] . ' ' . $row['Type'];
 226   
 227              if (!is_null($row['Default']))
 228              {
 229                  $line .= " DEFAULT '{$row['Default']}'";
 230              }
 231   
 232              if ($row['Null'] != 'YES')
 233              {
 234                  $line .= ' NOT NULL';
 235              }
 236   
 237              if ($row['Extra'] != '')
 238              {
 239                  $line .= ' ' . $row['Extra'];
 240              }
 241   
 242              $rows[] = $line;
 243          }
 244          $this->db->sql_freeresult($result);
 245   
 246          $sql = "SHOW KEYS
 247              FROM $table_name";
 248   
 249          $result = $this->db->sql_query($sql);
 250   
 251          $index = array();
 252          while ($row = $this->db->sql_fetchrow($result))
 253          {
 254              $kname = $row['Key_name'];
 255   
 256              if ($kname != 'PRIMARY')
 257              {
 258                  if ($row['Non_unique'] == 0)
 259                  {
 260                      $kname = "UNIQUE|$kname";
 261                  }
 262              }
 263   
 264              if ($row['Sub_part'])
 265              {
 266                  $row['Column_name'] .= '(' . $row['Sub_part'] . ')';
 267              }
 268              $index[$kname][] = $row['Column_name'];
 269          }
 270          $this->db->sql_freeresult($result);
 271   
 272          foreach ($index as $key => $columns)
 273          {
 274              $line = '   ';
 275   
 276              if ($key == 'PRIMARY')
 277              {
 278                  $line .= 'PRIMARY KEY (' . implode(', ', $columns) . ')';
 279              }
 280              else if (strpos($key, 'UNIQUE') === 0)
 281              {
 282                  $line .= 'UNIQUE ' . substr($key, 7) . ' (' . implode(', ', $columns) . ')';
 283              }
 284              else if (strpos($key, 'FULLTEXT') === 0)
 285              {
 286                  $line .= 'FULLTEXT ' . substr($key, 9) . ' (' . implode(', ', $columns) . ')';
 287              }
 288              else
 289              {
 290                  $line .= "KEY $key (" . implode(', ', $columns) . ')';
 291              }
 292   
 293              $rows[] = $line;
 294          }
 295   
 296          $sql_data .= implode(",\n", $rows);
 297          $sql_data .= "\n);\n\n";
 298   
 299          $this->flush($sql_data);
 300      }
 301  }
 302