您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

55 行
1.4KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\debug\actions\db;
  8. use yii\base\Action;
  9. use yii\debug\panels\DbPanel;
  10. use yii\web\HttpException;
  11. /**
  12. * ExplainAction provides EXPLAIN information for SQL queries
  13. *
  14. * @author Laszlo <github@lvlconsultancy.nl>
  15. * @since 2.0.6
  16. */
  17. class ExplainAction extends Action
  18. {
  19. /**
  20. * @var DbPanel
  21. */
  22. public $panel;
  23. public function run($seq, $tag)
  24. {
  25. $this->controller->loadData($tag);
  26. $timings = $this->panel->calculateTimings();
  27. if (!isset($timings[$seq])) {
  28. throw new HttpException(404, 'Log message not found.');
  29. }
  30. $query = $timings[$seq]['info'];
  31. $results = $this->panel->getDb()->createCommand('EXPLAIN ' . $query)->queryAll();
  32. $output[] = '<table class="table"><thead><tr>' . implode(array_map(function($key) {
  33. return '<th>' . $key . '</th>';
  34. }, array_keys($results[0]))) . '</tr></thead><tbody>';
  35. foreach ($results as $result) {
  36. $output[] = '<tr>' . implode(array_map(function($value) {
  37. return '<td>' . (empty($value) ? 'NULL' : htmlspecialchars($value)) . '</td>';
  38. }, $result)) . '</tr>';
  39. }
  40. $output[] = '</tbody></table>';
  41. return implode($output);
  42. }
  43. }