Database::logQuery PHP Method

logQuery() protected method

protected logQuery ( $sql, $queryResponse, $microtimeStart ) : boolean
return boolean Whether or not log info was actually generated and saved, false by default for performance reasons, can be enabled in the configuration file.
    protected function logQuery($sql, $queryResponse, $microtimeStart)
    {
        static $doLog;
        if ($doLog === null) {
            $doLog = $this->context->getConf()->debug->dbLogQueries;
        }
        if ($doLog) {
            $microtimeEnd = microtime(true);
            $backtrace = debug_backtrace(false);
            // 0:logQuery > 1:doQuery -> 2:(some Database method) -> 3:callee
            $backtrace = $backtrace[3];
            $backtrace = ($backtrace['class'] ? "{$backtrace['class']}::" : $backtrace['class']) . $backtrace['function'];
            $this->rawQueryHistory[] = array('sql' => $sql, 'caller' => $backtrace, 'numRows' => is_resource($queryResponse) ? $this->getNumRows($queryResponse) : null, 'insertId' => $this->getInsertId(), 'affectedRows' => $this->getAffectedRows(), 'queryTime' => $microtimeEnd - $microtimeStart);
        }
        return $doLog;
    }

Usage Example

Example #1
0
 /**
  * Stacks the queries made during the current DB incarnation.
  * @param string $query
  */
 public function recordQuery($query)
 {
     \Database::logQuery($query);
 }