Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

mysqli.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 10.18 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  * MySQLi Database Abstraction Layer
018  * mysqli-extension has to be compiled with:
019  * MySQL 4.1+ or MySQL 5.0+
020  */
021  class mysqli extends \phpbb\db\driver\mysql_base
022  {
023      var $multi_insert = true;
024      var $connect_error = '';
025   
026      /**
027      * {@inheritDoc}
028      */
029      function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
030      {
031          if (!function_exists('mysqli_connect'))
032          {
033              $this->connect_error = 'mysqli_connect function does not exist, is mysqli extension installed?';
034              return $this->sql_error('');
035          }
036   
037          $this->persistency = $persistency;
038          $this->user = $sqluser;
039   
040          // If persistent connection, set dbhost to localhost when empty and prepend it with 'p:' prefix
041          $this->server = ($this->persistency) ? 'p:' . (($sqlserver) ? $sqlserver : 'localhost') : $sqlserver;
042   
043          $this->dbname = $database;
044          $port = (!$port) ? null : $port;
045   
046          // If port is set and it is not numeric, most likely mysqli socket is set.
047          // Try to map it to the $socket parameter.
048          $socket = null;
049          if ($port)
050          {
051              if (is_numeric($port))
052              {
053                  $port = (int) $port;
054              }
055              else
056              {
057                  $socket = $port;
058                  $port = null;
059              }
060          }
061   
062          $this->db_connect_id = mysqli_init();
063   
064          if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS))
065          {
066              $this->db_connect_id = '';
067          }
068   
069          if ($this->db_connect_id && $this->dbname != '')
070          {
071              @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'");
072   
073              // enforce strict mode on databases that support it
074              if (version_compare($this->sql_server_info(true), '5.0.2', '>='))
075              {
076                  $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode');
077                  if ($result)
078                  {
079                      $row = mysqli_fetch_assoc($result);
080                      mysqli_free_result($result);
081   
082                      $modes = array_map('trim', explode(',', $row['sql_mode']));
083                  }
084                  else
085                  {
086                      $modes = array();
087                  }
088   
089                  // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES
090                  if (!in_array('TRADITIONAL', $modes))
091                  {
092                      if (!in_array('STRICT_ALL_TABLES', $modes))
093                      {
094                          $modes[] = 'STRICT_ALL_TABLES';
095                      }
096   
097                      if (!in_array('STRICT_TRANS_TABLES', $modes))
098                      {
099                          $modes[] = 'STRICT_TRANS_TABLES';
100                      }
101                  }
102   
103                  $mode = implode(',', $modes);
104                  @mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'");
105              }
106              return $this->db_connect_id;
107          }
108   
109          return $this->sql_error('');
110      }
111   
112      /**
113      * {@inheritDoc}
114      */
115      function sql_server_info($raw = false, $use_cache = true)
116      {
117          global $cache;
118   
119          if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false)
120          {
121              $result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version');
122              if ($result)
123              {
124                  $row = mysqli_fetch_assoc($result);
125                  mysqli_free_result($result);
126   
127                  $this->sql_server_version = $row['version'];
128   
129                  if (!empty($cache) && $use_cache)
130                  {
131                      $cache->put('mysqli_version', $this->sql_server_version);
132                  }
133              }
134          }
135   
136          return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version;
137      }
138   
139      /**
140      * SQL Transaction
141      * @access private
142      */
143      function _sql_transaction($status = 'begin')
144      {
145          switch ($status)
146          {
147              case 'begin':
148                  return @mysqli_autocommit($this->db_connect_id, false);
149              break;
150   
151              case 'commit':
152                  $result = @mysqli_commit($this->db_connect_id);
153                  @mysqli_autocommit($this->db_connect_id, true);
154                  return $result;
155              break;
156   
157              case 'rollback':
158                  $result = @mysqli_rollback($this->db_connect_id);
159                  @mysqli_autocommit($this->db_connect_id, true);
160                  return $result;
161              break;
162          }
163   
164          return true;
165      }
166   
167      /**
168      * {@inheritDoc}
169      */
170      function sql_query($query = '', $cache_ttl = 0)
171      {
172          if ($query != '')
173          {
174              global $cache;
175   
176              // EXPLAIN only in extra debug mode
177              if (defined('DEBUG'))
178              {
179                  $this->sql_report('start', $query);
180              }
181              else if (defined('PHPBB_DISPLAY_LOAD_TIME'))
182              {
183                  $this->curtime = microtime(true);
184              }
185   
186              $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false;
187              $this->sql_add_num_queries($this->query_result);
188   
189              if ($this->query_result === false)
190              {
191                  if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false)
192                  {
193                      $this->sql_error($query);
194                  }
195   
196                  if (defined('DEBUG'))
197                  {
198                      $this->sql_report('stop', $query);
199                  }
200                  else if (defined('PHPBB_DISPLAY_LOAD_TIME'))
201                  {
202                      $this->sql_time += microtime(true) - $this->curtime;
203                  }
204   
205                  if (!$this->query_result)
206                  {
207                      return false;
208                  }
209   
210                  if ($cache && $cache_ttl)
211                  {
212                      $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl);
213                  }
214              }
215              else if (defined('DEBUG'))
216              {
217                  $this->sql_report('fromcache', $query);
218              }
219          }
220          else
221          {
222              return false;
223          }
224   
225          return $this->query_result;
226      }
227   
228      /**
229      * {@inheritDoc}
230      */
231      function sql_affectedrows()
232      {
233          return ($this->db_connect_id) ? @mysqli_affected_rows($this->db_connect_id) : false;
234      }
235   
236      /**
237      * {@inheritDoc}
238      */
239      function sql_fetchrow($query_id = false)
240      {
241          global $cache;
242   
243          if ($query_id === false)
244          {
245              $query_id = $this->query_result;
246          }
247   
248          if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
249          {
250              return $cache->sql_fetchrow($query_id);
251          }
252   
253          if ($query_id)
254          {
255              $result = mysqli_fetch_assoc($query_id);
256              return $result !== null ? $result : false;
257          }
258   
259          return false;
260      }
261   
262      /**
263      * {@inheritDoc}
264      */
265      function sql_rowseek($rownum, &$query_id)
266      {
267          global $cache;
268   
269          if ($query_id === false)
270          {
271              $query_id = $this->query_result;
272          }
273   
274          if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
275          {
276              return $cache->sql_rowseek($rownum, $query_id);
277          }
278   
279          return ($query_id) ? @mysqli_data_seek($query_id, $rownum) : false;
280      }
281   
282      /**
283      * {@inheritDoc}
284      */
285      function sql_nextid()
286      {
287          return ($this->db_connect_id) ? @mysqli_insert_id($this->db_connect_id) : false;
288      }
289   
290      /**
291      * {@inheritDoc}
292      */
293      function sql_freeresult($query_id = false)
294      {
295          global $cache;
296   
297          if ($query_id === false)
298          {
299              $query_id = $this->query_result;
300          }
301   
302          if ($cache && !is_object($query_id) && $cache->sql_exists($query_id))
303          {
304              return $cache->sql_freeresult($query_id);
305          }
306   
307          if (!$query_id)
308          {
309              return false;
310          }
311   
312          if ($query_id === true)
313          {
314              return true;
315          }
316   
317          return mysqli_free_result($query_id);
318      }
319   
320      /**
321      * {@inheritDoc}
322      */
323      function sql_escape($msg)
324      {
325          return @mysqli_real_escape_string($this->db_connect_id, $msg);
326      }
327   
328      /**
329      * return sql error array
330      * @access private
331      */
332      function _sql_error()
333      {
334          if ($this->db_connect_id)
335          {
336              $error = array(
337                  'message'    => @mysqli_error($this->db_connect_id),
338                  'code'        => @mysqli_errno($this->db_connect_id)
339              );
340          }
341          else if (function_exists('mysqli_connect_error'))
342          {
343              $error = array(
344                  'message'    => @mysqli_connect_error(),
345                  'code'        => @mysqli_connect_errno(),
346              );
347          }
348          else
349          {
350              $error = array(
351                  'message'    => $this->connect_error,
352                  'code'        => '',
353              );
354          }
355   
356          return $error;
357      }
358   
359      /**
360      * Close sql connection
361      * @access private
362      */
363      function _sql_close()
364      {
365          return @mysqli_close($this->db_connect_id);
366      }
367   
368      /**
369      * Build db-specific report
370      * @access private
371      */
372      function _sql_report($mode, $query = '')
373      {
374          static $test_prof;
375   
376          // current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING
377          if ($test_prof === null)
378          {
379              $test_prof = false;
380              if (strpos(mysqli_get_server_info($this->db_connect_id), 'community') !== false)
381              {
382                  $ver = mysqli_get_server_version($this->db_connect_id);
383                  if ($ver >= 50037 && $ver < 50100)
384                  {
385                      $test_prof = true;
386                  }
387              }
388          }
389   
390          switch ($mode)
391          {
392              case 'start':
393   
394                  $explain_query = $query;
395                  if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
396                  {
397                      $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
398                  }
399                  else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m))
400                  {
401                      $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
402                  }
403   
404                  if (preg_match('/^SELECT/', $explain_query))
405                  {
406                      $html_table = false;
407   
408                      // begin profiling
409                      if ($test_prof)
410                      {
411                          @mysqli_query($this->db_connect_id, 'SET profiling = 1;');
412                      }
413   
414                      if ($result = @mysqli_query($this->db_connect_id, "EXPLAIN $explain_query"))
415                      {
416                          while ($row = mysqli_fetch_assoc($result))
417                          {
418                              $html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
419                          }
420                          mysqli_free_result($result);
421                      }
422   
423                      if ($html_table)
424                      {
425                          $this->html_hold .= '</table>';
426                      }
427   
428                      if ($test_prof)
429                      {
430                          $html_table = false;
431   
432                          // get the last profile
433                          if ($result = @mysqli_query($this->db_connect_id, 'SHOW PROFILE ALL;'))
434                          {
435                              $this->html_hold .= '<br />';
436                              while ($row = mysqli_fetch_assoc($result))
437                              {
438                                  // make <unknown> HTML safe
439                                  if (!empty($row['Source_function']))
440                                  {
441                                      $row['Source_function'] = str_replace(array('<', '>'), array('&lt;', '&gt;'), $row['Source_function']);
442                                  }
443   
444                                  // remove unsupported features
445                                  foreach ($row as $key => $val)
446                                  {
447                                      if ($val === null)
448                                      {
449                                          unset($row[$key]);
450                                      }
451                                  }
452                                  $html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
453                              }
454                              mysqli_free_result($result);
455                          }
456   
457                          if ($html_table)
458                          {
459                              $this->html_hold .= '</table>';
460                          }
461   
462                          @mysqli_query($this->db_connect_id, 'SET profiling = 0;');
463                      }
464                  }
465   
466              break;
467   
468              case 'fromcache':
469                  $endtime = explode(' ', microtime());
470                  $endtime = $endtime[0] + $endtime[1];
471   
472                  $result = @mysqli_query($this->db_connect_id, $query);
473                  if ($result)
474                  {
475                      while ($void = mysqli_fetch_assoc($result))
476                      {
477                          // Take the time spent on parsing rows into account
478                      }
479                      mysqli_free_result($result);
480                  }
481   
482                  $splittime = explode(' ', microtime());
483                  $splittime = $splittime[0] + $splittime[1];
484   
485                  $this->sql_report('record_fromcache', $query, $endtime, $splittime);
486   
487              break;
488          }
489      }
490  }
491