Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #166

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
160 changes: 83 additions & 77 deletions library/includes/core/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class sql_db

var $DBS = array();

var $engine = 'MySQL';

/**
* Constructor
*/
Expand Down Expand Up @@ -95,11 +97,12 @@ function connect ()
{
$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'));
Expand Down Expand Up @@ -911,81 +914,84 @@ function explain ($mode, $html_table = '', $row = '')

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]";
}

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 .= '</table>';
}
}
break;

case 'stop':
if (!$this->explain_hold) break;

$id = $this->dbg_id-1;
$htid = 'expl-'. intval($this->link) .'-'. $id;
$dbg = $this->dbg[$id];

$this->explain_out .= '
<table width="98%" cellpadding="0" cellspacing="0" class="bodyline row2 bCenter" style="border-bottom: 0px;">
<tr>
<th style="height: 22px; cursor: pointer;" align="left">&nbsp;'. $dbg['src'] .'&nbsp; ['. sprintf('%.4f', $dbg['time']) .' s]&nbsp; <i>'. $dbg['info'] .'</i></th>
<th style="height: 22px; cursor: pointer;" align="right" title="Copy to clipboard" onclick="$(\'#'. $htid .'\').CopyToClipboard();">'. "$this->db_server.$this->selected_db" .' :: Query #'. ($this->num_queries+1) .'&nbsp;</th>
</tr>
<tr><td colspan="2">'. $this->explain_hold .'</td></tr>
</table>
<div class="sqlLog"><div id="'. $htid .'" class="sqlLogRow sqlExplain" style="padding: 0px;">'. short_query($dbg['sql'], true) .'&nbsp;&nbsp;</div></div>
<br />';
break;

case 'add_explain_row':
if (!$html_table && $row)
{
$html_table = true;
$this->explain_hold .= '<table width="100%" cellpadding="3" cellspacing="1" class="bodyline" style="border-width: 0;"><tr>';
foreach (array_keys($row) as $val)
{
$this->explain_hold .= '<td class="row3 gensmall" align="center"><b>'. $val .'</b></td>';
}
$this->explain_hold .= '</tr>';
}
$this->explain_hold .= '<tr>';
foreach (array_values($row) as $i => $val)
{
$class = !($i % 2) ? 'row1' : 'row2';
$this->explain_hold .= '<td class="'. $class .' gen">'. str_replace(array("{$this->selected_db}.", ',', ';'), array('', ', ', ';<br />'), $val) .'</td>';
}
$this->explain_hold .= '</tr>';

return $html_table;

break;

case 'display':
echo '<a name="explain"></a><div class="med">'. $this->explain_out .'</div>';
break;
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 ($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 .= '</table>';
}
}
break;

case 'stop':
if (!$this->explain_hold) break;

$id = $this->dbg_id-1;
$htid = 'expl-'. intval($this->link) .'-'. $id;
$dbg = $this->dbg[$id];

$this->explain_out .= '
<table width="98%" cellpadding="0" cellspacing="0" class="bodyline row2 bCenter" style="border-bottom: 0px;">
<tr>
<th style="height: 22px; cursor: pointer;" align="left">&nbsp;'. $dbg['src'] .'&nbsp; ['. sprintf('%.4f', $dbg['time']) .' s]&nbsp; <i>'. $dbg['info'] .'</i></th>
<th style="height: 22px; cursor: pointer;" align="right" title="Copy to clipboard" onclick="$(\'#'. $htid .'\').CopyToClipboard();">'. "[$this->engine] $this->db_server.$this->selected_db" .' :: Query #'. ($this->num_queries+1) .'&nbsp;</th>
</tr>
<tr><td colspan="2">'. $this->explain_hold .'</td></tr>
</table>
<div class="sqlLog"><div id="'. $htid .'" class="sqlLogRow sqlExplain" style="padding: 0px;">'. short_query($dbg['sql'], true) .'&nbsp;&nbsp;</div></div>
<br />';
break;

case 'add_explain_row':
if (!$html_table && $row)
{
$html_table = true;
$this->explain_hold .= '<table width="100%" cellpadding="3" cellspacing="1" class="bodyline" style="border-width: 0;"><tr>';
foreach (array_keys($row) as $val)
{
$this->explain_hold .= '<td class="row3 gensmall" align="center"><b>'. $val .'</b></td>';
}
$this->explain_hold .= '</tr>';
}
$this->explain_hold .= '<tr>';
foreach (array_values($row) as $i => $val)
{
$class = !($i % 2) ? 'row1' : 'row2';
$this->explain_hold .= '<td class="'. $class .' gen">'. str_replace(array("{$this->selected_db}.", ',', ';'), array('', ', ', ';<br />'), $val) .'</td>';
}
$this->explain_hold .= '</tr>';

return $html_table;
break;

case 'display':
echo '<a name="explain"></a><div class="med">'. $this->explain_out .'</div>';
break;

default:
die("Invalid {$this->engine} explain mode");
break;
}
}
}
2 changes: 1 addition & 1 deletion library/includes/functions_dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down