Nette\Database\Helpers::dumpResult PHP Method

dumpResult() public static method

Displays complete result set as HTML table for debug purposes.
public static dumpResult ( ResultSet $result ) : void
$result ResultSet
return void
    public static function dumpResult(ResultSet $result)
    {
        echo "\n<table class=\"dump\">\n<caption>" . htmlSpecialChars($result->getQueryString(), ENT_IGNORE, 'UTF-8') . "</caption>\n";
        if (!$result->getColumnCount()) {
            echo "\t<tr>\n\t\t<th>Affected rows:</th>\n\t\t<td>", $result->getRowCount(), "</td>\n\t</tr>\n</table>\n";
            return;
        }
        $i = 0;
        foreach ($result as $row) {
            if ($i === 0) {
                echo "<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
                foreach ($row as $col => $foo) {
                    echo "\t\t<th>" . htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8') . "</th>\n";
                }
                echo "\t</tr>\n</thead>\n<tbody>\n";
            }
            echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
            foreach ($row as $col) {
                echo "\t\t<td>", htmlSpecialChars($col, ENT_NOQUOTES, 'UTF-8'), "</td>\n";
            }
            echo "\t</tr>\n";
            $i++;
        }
        if ($i === 0) {
            echo "\t<tr>\n\t\t<td><em>empty result set</em></td>\n\t</tr>\n</table>\n";
        } else {
            echo "</tbody>\n</table>\n";
        }
    }

Usage Example

 /**
  * Suggested behavior: print Tracy\Dumper::toHtml() array
  * of returned rows so row count is immediately visible.
  *
  * @return Html|string
  */
 public function getResult()
 {
     ob_start();
     NDB\Helpers::dumpResult($this->result);
     return ob_get_clean();
 }
All Usage Examples Of Nette\Database\Helpers::dumpResult