diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6a0a04..85a1068a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ - Use constants instead of string literals [\#151](https://github.com/torrentpier/torrentpier-lts/pull/151), [\#160](https://github.com/torrentpier/torrentpier-lts/pull/160) ([belomaxorka](https://github.com/belomaxorka)) - Sync language (html dir) with latest sources [\#152](https://github.com/torrentpier/torrentpier-lts/pull/152) ([belomaxorka](https://github.com/belomaxorka)) - Updated UK lang icons [\#155](https://github.com/torrentpier/torrentpier-lts/pull/155) ([belomaxorka](https://github.com/belomaxorka)) -- Minor fixes [\#124](https://github.com/torrentpier/torrentpier-lts/pull/124), [\#133](https://github.com/torrentpier/torrentpier-lts/pull/133), [\#135](https://github.com/torrentpier/torrentpier-lts/pull/135), [\#136](https://github.com/torrentpier/torrentpier-lts/pull/136), [\#139](https://github.com/torrentpier/torrentpier-lts/pull/139), [\#142](https://github.com/torrentpier/torrentpier-lts/pull/142), [\#144](https://github.com/torrentpier/torrentpier-lts/pull/144), [\#145](https://github.com/torrentpier/torrentpier-lts/pull/145), [\#148](https://github.com/torrentpier/torrentpier-lts/pull/148), [\#153](https://github.com/torrentpier/torrentpier-lts/pull/153), [\#154](https://github.com/torrentpier/torrentpier-lts/pull/154), [\#156](https://github.com/torrentpier/torrentpier-lts/pull/156), [\#157](https://github.com/torrentpier/torrentpier-lts/pull/157), [\#158](https://github.com/torrentpier/torrentpier-lts/pull/158), [\#159](https://github.com/torrentpier/torrentpier-lts/pull/159), [\#162](https://github.com/torrentpier/torrentpier-lts/pull/162), [\#163](https://github.com/torrentpier/torrentpier-lts/pull/163), [\#164](https://github.com/torrentpier/torrentpier-lts/pull/164), [\#165](https://github.com/torrentpier/torrentpier-lts/pull/165) ([belomaxorka](https://github.com/belomaxorka)) +- Minor fixes [\#124](https://github.com/torrentpier/torrentpier-lts/pull/124), [\#133](https://github.com/torrentpier/torrentpier-lts/pull/133), [\#135](https://github.com/torrentpier/torrentpier-lts/pull/135), [\#136](https://github.com/torrentpier/torrentpier-lts/pull/136), [\#139](https://github.com/torrentpier/torrentpier-lts/pull/139), [\#142](https://github.com/torrentpier/torrentpier-lts/pull/142), [\#144](https://github.com/torrentpier/torrentpier-lts/pull/144), [\#145](https://github.com/torrentpier/torrentpier-lts/pull/145), [\#148](https://github.com/torrentpier/torrentpier-lts/pull/148), [\#153](https://github.com/torrentpier/torrentpier-lts/pull/153), [\#154](https://github.com/torrentpier/torrentpier-lts/pull/154), [\#156](https://github.com/torrentpier/torrentpier-lts/pull/156), [\#157](https://github.com/torrentpier/torrentpier-lts/pull/157), [\#158](https://github.com/torrentpier/torrentpier-lts/pull/158), [\#159](https://github.com/torrentpier/torrentpier-lts/pull/159), [\#162](https://github.com/torrentpier/torrentpier-lts/pull/162), [\#163](https://github.com/torrentpier/torrentpier-lts/pull/163), [\#164](https://github.com/torrentpier/torrentpier-lts/pull/164), [\#165](https://github.com/torrentpier/torrentpier-lts/pull/165), [\#166](https://github.com/torrentpier/torrentpier-lts/pull/166) ([belomaxorka](https://github.com/belomaxorka)) ## [v2.1.5-2023.03](https://github.com/torrentpier/torrentpier-lts/tree/v2.1.5-2023.03) (2023-04-04) [Full Changelog](https://github.com/torrentpier/torrentpier-lts/compare/v2.1.5-2023.03...main) diff --git a/library/includes/core/mysql.php b/library/includes/core/mysql.php index 5b3965cc..145032e8 100644 --- a/library/includes/core/mysql.php +++ b/library/includes/core/mysql.php @@ -35,6 +35,8 @@ class sql_db var $DBS = array(); + var $engine = 'MySQL'; + /** * Constructor */ @@ -95,11 +97,12 @@ class sql_db { $server = (DBG_USER) ? $this->cfg['dbhost'] : ''; header("HTTP/1.0 503 Service Unavailable"); + $con_error = "Could not connect to {$this->engine} server $server"; if (DBG_USER) { - dbg_log("Could not connect to mysql server $server", "{$server}-DB-connect-FAIL_" . time()); + dbg_log($con_error, "{$server}-DB-connect-FAIL_" . time()); } - die("Could not connect to mysql server $server"); + die($con_error); } register_shutdown_function(array(&$this, 'close')); @@ -911,81 +914,84 @@ class sql_db switch ($mode) { - case 'start': - $this->explain_hold = ''; - // TODO: добавить поддержку многотабличных запросов - if (preg_match('#UPDATE ([a-z0-9_]+).*?WHERE(.*)/#', $query, $m)) - { - $query = "SELECT * FROM $m[1] WHERE $m[2]"; - } - else if (preg_match('#DELETE FROM ([a-z0-9_]+).*?WHERE(.*)#s', $query, $m)) - { - $query = "SELECT * FROM $m[1] WHERE $m[2]"; - } + case 'start': + $this->explain_hold = ''; + // TODO: добавить поддержку многотабличных запросов + if (preg_match('#UPDATE ([a-z0-9_]+).*?WHERE(.*)/#', $query, $m)) + { + $query = "SELECT * FROM $m[1] WHERE $m[2]"; + } + else if (preg_match('#DELETE FROM ([a-z0-9_]+).*?WHERE(.*)#s', $query, $m)) + { + $query = "SELECT * FROM $m[1] WHERE $m[2]"; + } - if (preg_match('#^SELECT#', $query)) - { - $html_table = false; + if (preg_match('#^SELECT#', $query)) + { + $html_table = false; - if ($result = @mysql_query("EXPLAIN $query", $this->link)) - { - while ($row = @mysql_fetch_assoc($result)) - { - $html_table = $this->explain('add_explain_row', $html_table, $row); - } - } - if ($html_table) - { - $this->explain_hold .= ''; - } - } - break; + if ($result = @mysql_query("EXPLAIN $query", $this->link)) + { + while ($row = @mysql_fetch_assoc($result)) + { + $html_table = $this->explain('add_explain_row', $html_table, $row); + } + } + if ($html_table) + { + $this->explain_hold .= ''; + } + } + break; - case 'stop': - if (!$this->explain_hold) break; + case 'stop': + if (!$this->explain_hold) break; - $id = $this->dbg_id-1; - $htid = 'expl-'. intval($this->link) .'-'. $id; - $dbg = $this->dbg[$id]; + $id = $this->dbg_id-1; + $htid = 'expl-'. intval($this->link) .'-'. $id; + $dbg = $this->dbg[$id]; - $this->explain_out .= ' - - - - - - -
 '. $dbg['src'] .'  ['. sprintf('%.4f', $dbg['time']) .' s]  '. $dbg['info'] .''. "$this->db_server.$this->selected_db" .' :: Query #'. ($this->num_queries+1) .' 
'. $this->explain_hold .'
-
'. short_query($dbg['sql'], true) .'  
-
'; - break; + $this->explain_out .= ' + + + + + + +
 '. $dbg['src'] .'  ['. sprintf('%.4f', $dbg['time']) .' s]  '. $dbg['info'] .''. "[$this->engine] $this->db_server.$this->selected_db" .' :: Query #'. ($this->num_queries+1) .' 
'. $this->explain_hold .'
+
'. short_query($dbg['sql'], true) .'  
+
'; + break; - case 'add_explain_row': - if (!$html_table && $row) - { - $html_table = true; - $this->explain_hold .= ''; - foreach (array_keys($row) as $val) - { - $this->explain_hold .= ''; - } - $this->explain_hold .= ''; - } - $this->explain_hold .= ''; - foreach (array_values($row) as $i => $val) - { - $class = !($i % 2) ? 'row1' : 'row2'; - $this->explain_hold .= ''; - } - $this->explain_hold .= ''; + case 'add_explain_row': + if (!$html_table && $row) + { + $html_table = true; + $this->explain_hold .= '
'. $val .'
'. str_replace(array("{$this->selected_db}.", ',', ';'), array('', ', ', ';
'), $val) .'
'; + foreach (array_keys($row) as $val) + { + $this->explain_hold .= ''; + } + $this->explain_hold .= ''; + } + $this->explain_hold .= ''; + foreach (array_values($row) as $i => $val) + { + $class = !($i % 2) ? 'row1' : 'row2'; + $this->explain_hold .= ''; + } + $this->explain_hold .= ''; - return $html_table; + return $html_table; + break; - break; + case 'display': + echo '
'. $this->explain_out .'
'; + break; - case 'display': - echo '
'. $this->explain_out .'
'; - break; + default: + die("Invalid {$this->engine} explain mode"); + break; } } } \ No newline at end of file diff --git a/library/includes/functions_dev.php b/library/includes/functions_dev.php index ae5718e4..31168f90 100644 --- a/library/includes/functions_dev.php +++ b/library/includes/functions_dev.php @@ -10,7 +10,7 @@ function get_sql_log () foreach ($DBS->srv as $srv_name => $db_obj) { - $log .= !empty($db_obj) ? get_sql_log_html($db_obj, "$srv_name [MySQL]") : ''; + $log .= !empty($db_obj) ? get_sql_log_html($db_obj, "database: $srv_name [{$db_obj->engine}]") : ''; } foreach ($CACHES->obj as $cache_name => $cache_obj)
'. $val .'
'. str_replace(array("{$this->selected_db}.", ',', ';'), array('', ', ', ';
'), $val) .'