Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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