Class yii\debug\actions\db\ExplainAction
| Inheritance | yii\debug\actions\db\ExplainAction » yii\base\Action |
|---|---|
| Available since extension's version | 2.0.6 |
| Source Code | https://github.com/yiisoft/yii2-debug/blob/master/src/actions/db/ExplainAction.php |
ExplainAction provides EXPLAIN information for SQL queries
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $panel | yii\debug\panels\DbPanel | yii\debug\actions\db\ExplainAction |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| run() | Runs the action. | yii\debug\actions\db\ExplainAction |
Property Details
Method Details
Runs the action.
| public string run ( $seq, $tag ) | ||
| $seq | string | |
| $tag | string | |
| throws | \yii\web\HttpException | |
|---|---|---|
| throws | \yii\db\Exception | |
| throws | \yii\web\NotFoundHttpException |
if the view file cannot be found |
| throws | \yii\base\InvalidConfigException | |
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'];
$results = $this->panel->getDb()->createCommand('EXPLAIN ' . $query)->queryAll();
$output[] = '<table class="table"><thead><tr>' . implode(array_map(function ($key) {
return '<th>' . $key . '</th>';
}, array_keys($results[0]))) . '</tr></thead><tbody>';
foreach ($results as $result) {
$output[] = '<tr>' . implode(array_map(function ($value) {
return '<td>' . (empty($value) ? 'NULL' : htmlspecialchars($value)) . '</td>';
}, $result)) . '</tr>';
}
$output[] = '</tbody></table>';
return implode($output);
}