コード例 #1
0
ファイル: Connection.php プロジェクト: janlanger/dibi
 /**
  * Generates and prints SQL query.
  * @param  array|mixed  one or more arguments
  * @return bool
  */
 public final function test($args)
 {
     $args = func_get_args();
     try {
         Helpers::dump($this->translateArgs($args));
         return TRUE;
     } catch (Exception $e) {
         if ($e->getSql()) {
             Helpers::dump($e->getSql());
         } else {
             echo get_class($e) . ': ' . $e->getMessage() . (PHP_SAPI === 'cli' ? "\n" : '<br>');
         }
         return FALSE;
     }
 }
コード例 #2
0
ファイル: Panel.php プロジェクト: heximcz/routerboard-backup
    /**
     * Returns HTML code for custom panel. (Tracy\IBarPanel)
     * @return mixed
     */
    public function getPanel()
    {
        $totalTime = $s = NULL;
        $h = 'htmlSpecialChars';
        foreach ($this->events as $event) {
            $totalTime += $event->time;
            $explain = NULL;
            // EXPLAIN is called here to work SELECT FOUND_ROWS()
            if ($this->explain && $event->type === Event::SELECT) {
                try {
                    $backup = [$event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime];
                    $event->connection->onEvent = NULL;
                    $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN');
                    $explain = Helpers::dump(@$event->connection->nativeQuery("{$cmd} {$event->sql}"), TRUE);
                } catch (Dibi\Exception $e) {
                }
                list($event->connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime) = $backup;
            }
            $s .= '<tr><td>' . sprintf('%0.3f', $event->time * 1000);
            if ($explain) {
                static $counter;
                $counter++;
                $s .= "<br /><a href='#tracy-debug-DibiProfiler-row-{$counter}' class='tracy-toggle tracy-collapsed' rel='#tracy-debug-DibiProfiler-row-{$counter}'>explain</a>";
            }
            $s .= '</td><td class="tracy-DibiProfiler-sql">' . Helpers::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, TRUE);
            if ($explain) {
                $s .= "<div id='tracy-debug-DibiProfiler-row-{$counter}' class='tracy-collapsed'>{$explain}</div>";
            }
            if ($event->source) {
                $s .= Tracy\Helpers::editorLink($event->source[0], $event->source[1]);
                //->class('tracy-DibiProfiler-source');
            }
            $s .= "</td><td>{$event->count}</td><td>{$h($event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'))}</td></tr>";
        }
        return empty($this->events) ? '' : '<style> #tracy-debug td.tracy-DibiProfiler-sql { background: white !important }
			#tracy-debug .tracy-DibiProfiler-source { color: #999 !important }
			#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
			<h1>Queries: ' . count($this->events) . ($totalTime === NULL ? '' : sprintf(', time: %0.3f ms', $totalTime * 1000)) . '</h1>
			<div class="tracy-inner tracy-DibiProfiler">
			<table>
				<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Rows</th><th>Connection</th></tr>' . $s . '
			</table>
			</div>';
    }