DboSource::logQuery PHP Method

logQuery() public method

Log given SQL query.
public logQuery ( string $sql, array $params = [] ) : void
$sql string SQL statement
$params array Values binded to the query (prepared statements)
return void
    public function logQuery($sql, $params = array())
    {
        $this->_queriesCnt++;
        $this->_queriesTime += $this->took;
        $this->_queriesLog[] = array('query' => $sql, 'params' => $params, 'affected' => $this->affected, 'numRows' => $this->numRows, 'took' => $this->took);
        if (count($this->_queriesLog) > $this->_queriesLogMax) {
            array_shift($this->_queriesLog);
        }
    }

Usage Example

    /**
     * logQuery method
     *
     * Set timers, errors and refer to the parent
     * If there are arguments passed - inject them into the query
     * Show MongoIds in a copy-and-paste-into-mongo format
     *
     *
     * @param mixed $query
     * @param array $args array()
     * @return void
     * @access public
     */
    public function logQuery($query, $args = array()) {
        if ($args) {
            $this->_stringify($args);
            $query = String::insert($query, $args);
        }
        $this->took = round((microtime(true) - $this->_startTime) * 1000, 0);
        $this->affected = null;
        if (empty($this->error['err'])) {
            $this->error = $this->_db->lastError();
            if (!is_scalar($this->error)) {
                $this->error = json_encode($this->error);
            }
        }
        $this->numRows = !empty($args['count']) ? $args['count'] : null;

        $query = preg_replace('@"ObjectId\((.*?)\)"@', 'ObjectId ("\1")', $query);
        return parent::logQuery($query);
    }
All Usage Examples Of DboSource::logQuery
DboSource