src/ORM/Connect/Database.php
protected function benchmarkQuery($sql, $callback, $parameters = array())
    {
        if (isset($_REQUEST['showqueries']) && Director::isDev()) {
            $this->queryCount++;
            $starttime = microtime(true);
            $result = $callback($sql);
            $endtime = round(microtime(true) - $starttime, 4);
            // replace parameters as closely as possible to what we'd expect the DB to put in
            if (in_array(strtolower($_REQUEST['showqueries']), ['inline', 'backtrace'])) {
                $sql = DB::inline_parameters($sql, $parameters);
            }
            $queryCount = sprintf("%04d", $this->queryCount);
            Debug::message("\n$queryCount: $sql\n{$endtime}s\n", false);

            // Show a backtrace if ?showqueries=backtrace
            if ($_REQUEST['showqueries'] === 'backtrace') {
                Backtrace::backtrace();
            }
            return $result;
        } else {
            return $callback($sql);
        }
    }
protected function benchmarkQuery($sql, $callback, $parameters = array())
    {
        if (isset($_REQUEST['showqueries']) && Director::isDev()) {
            $this->queryCount++;
            $starttime = microtime(true);
            $result = $callback($sql);
            $endtime = round(microtime(true) - $starttime, 4);
            // replace parameters as closely as possible to what we'd expect the DB to put in
            if (in_array(strtolower($_REQUEST['showqueries']), ['inline', 'backtrace'])) {
                $sql = DB::inline_parameters($sql, $parameters);
            }
            $queryCount = sprintf("%04d", $this->queryCount);
            Debug::message("\n$queryCount: $sql\n{$endtime}s\n", false);

            // Show a backtrace if ?showqueries=backtrace
            if ($_REQUEST['showqueries'] === 'backtrace') {
                Backtrace::backtrace();
            }
            return $result;
        } else {
            return $callback($sql);
        }
    }
protected function benchmarkQuery ( $ sql , $ callback , $ parameters = array ( ) ) { if ( isset ( $ _REQUEST [ 'showqueries' ] ) && Director :: isDev ( ) ) { $ this -> queryCount ++ ; $ starttime = microtime ( true ) ; $ result = $ callback ( $ sql ) ; $ endtime = round ( microtime ( true ) - $ starttime , 4 ) ; // replace parameters as closely as possible to what we'd expect the DB to put in if ( in_array ( strtolower ( $ _REQUEST [ 'showqueries' ] ) , [ 'inline' , 'backtrace' ] ) ) { $ sql = DB :: inline_parameters ( $ sql , $ parameters ) ; } $ queryCount = sprintf ( "%04d" , $ this -> queryCount ) ; Debug :: message ( "\n$queryCount: $sql\n{$endtime}s\n" , false ) ; // Show a backtrace if ?showqueries=backtrace if ( $ _REQUEST [ 'showqueries' ] === 'backtrace' ) { Backtrace :: backtrace ( ) ; } return $ result ; } else { return $ callback ( $ sql ) ; } }
Allows the display and benchmarking of queries as they are being run

@param string $sql Query to run, and single parameter to callback
@param callable $callback Callback to execute code
@param array $parameters Parameters for any parameterised query
@return mixed Result of query
Allows the display and benchmarking of queries as they are being run