コード例 #1
0
ファイル: jbmodel.php プロジェクト: alexmixaylov/real
 /**
  * Render explain table
  * Function ported from Joomla debug plugin
  * @param JBDatabaseQuery $select
  * @return null|string
  */
 protected function _explain(JBDatabaseQuery $select)
 {
     if (!(class_exists('jbdump') || JDEBUG)) {
         return null;
     }
     $table = $this->app->database->queryAssocList('EXPLAIN ' . $select->__toString());
     if (!$table) {
         return null;
     }
     $html = array();
     $html[] = '<table class="table" style="width:1600px"><tr>';
     foreach (array_keys($table[0]) as $k) {
         $html[] = '<th>' . htmlspecialchars($k) . '</th>';
     }
     $html[] = '</tr>';
     foreach ($table as $tr) {
         $html[] = '<tr>';
         foreach ($tr as $k => $td) {
             if ($td === null) {
                 $td = 'NULL';
             }
             if ($k == 'Error') {
                 $html[] = '<td class="dbg-warning">' . htmlspecialchars($td);
             } elseif ($k == 'key') {
                 if ($td === 'NULL') {
                     $html[] = '<td><strong style="color:#f00;">NO_INDEX</strong>';
                 } else {
                     $html[] = '<td><strong>' . htmlspecialchars($td) . '</strong>';
                 }
             } elseif ($k == 'Extra') {
                 $htmlTd = htmlspecialchars($td);
                 $htmlTd = preg_replace('/([^;]) /', '\\1&nbsp;', $htmlTd);
                 $htmlTdWithWarnings = str_replace('Using&nbsp;filesort', '<strong style="color:#f00;">USE_FILESORT</strong>', $htmlTd);
                 $html[] = '<td>' . $htmlTdWithWarnings;
             } elseif ($k == 'possible_keys') {
                 $td = str_replace(',', ",\n", $td);
                 $html[] = '<td>' . htmlspecialchars($td);
             } else {
                 $html[] = '<td>' . htmlspecialchars($td);
             }
             $html[] = '</td>';
         }
         $html[] = '</tr>';
     }
     $html[] = '</table>';
     $result = implode(PHP_EOL, $html);
     jbdump::sql($select);
     dump($result, 0, 'Explain::html');
 }