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
    /**
     * 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);
    }
Exemplo n.º 2
0
 /**
  * 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 = CakeText::insert($query, $args);
     }
     $this->took = round((microtime(true) - $this->_startTime) * 1000, 0);
     $this->affected = null;
     $this->numRows = !empty($args['count']) ? $args['count'] : null;
     $query = preg_replace('@"ObjectId\\((.*?)\\)"@', 'ObjectId ("\\1")', $query);
     return parent::logQuery($query);
 }