/**
  * Perform a MySQL database query, using current database connection.
  *
  * More information can be found on the codex page.
  *
  * @since 0.1
  *
  * @param string $query Database query
  * @return int|false Number of rows affected/selected or false on error
  */
 public function query($query)
 {
     $return_val = 0;
     $this->flush_var();
     $this->last_query = $query;
     $this->result = $this->mysqli->query($query);
     // If there is an error then take note of it..
     if ($this->mysqli->errno) {
         $this->json_response->makeError($this->exception, $this->mysqli->error);
         $this->print_error();
         return false;
     }
     if (preg_match('/^\\s*(create|alter|truncate|drop) /i', $query)) {
         $return_val = $this->result;
     } elseif (preg_match('/^\\s*(insert|delete|update|replace) /i', $query)) {
         $this->affected_rows = $this->mysqli->affected_rows;
         // Take note of the insert_id
         if (preg_match('/^\\s*(insert|replace) /i', $query)) {
             $this->insert_id = $this->mysqli->insert_id;
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         $i = 0;
         while ($i < @$this->result->field_count) {
             $this->column_info[$i] = @$this->result->fetch_field();
             $i++;
         }
         $num_rows = 0;
         while ($row = @$this->result->fetch_object()) {
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         $this->result->free();
         // Log number of rows the query returned
         // and return number of rows selected
         $this->num_rows = $num_rows;
         $return_val = $num_rows;
     }
     return $return_val;
 }