ExplainAction.php
988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace yii\debug\actions\db;
use yii\base\Action;
use yii\debug\panels\DbPanel;
use yii\web\HttpException;
/**
* ExplainAction provides EXPLAIN information for SQL queries
*/
class ExplainAction extends Action
{
/**
* @var DbPanel
*/
public $panel;
public function run($seq, $tag)
{
$this->controller->loadData($tag);
$timings = $this->panel->calculateTimings();
if (!isset($timings[$seq])) {
throw new HttpException(404, 'Log message not found.');
}
$query = $timings[$seq]['info'];
$result = $this->panel->getDb()->createCommand('EXPLAIN ' . $query)->queryOne();
if (isset($result['id'])) {
unset($result['id']);
}
$output = [];
foreach ($result as $key => $value) {
if ($value) {
$output[] = sprintf('<b>%s</b>: %s', $key, $value);
}
}
return implode('<br/>', $output);
}
}