Example #1
0
File: MySQL.php Project: jasny/Q
 /**
  * Actually execute a query.
  * Logs statement and result if a logger is set.
  *
  * @return mysqli_result
  */
 public function nativeQuery($statement)
 {
     // Logging disabled
     if (!isset($this->log)) {
         return $this->native->query($statement);
     }
     // Logging enabled
     $sec = microtime(true);
     $result = $this->native->query($statement);
     $time = microtime(true) - $sec;
     unset($sec);
     $count = is_object($result) ? $result->num_rows : $this->native->affected_rows;
     $errno = $this->native->errno;
     $error = $this->native->error;
     $rows = array();
     if (isset($this->logSettings['rows'])) {
         if (function_exists('mysqli_fetch_all')) {
             $rows = $this->native->fetch_all(MYSQLI_NUM);
         } else {
             while ($row = $this->native->fetch_row()) {
                 $rows[] = $row;
             }
         }
         break;
     }
     $args = call_user_func_array('compact', $this->logColumns);
     $this->log->write($args, 'db-query');
     return $result;
 }