/**
  * Returns an array containing all of the result set rows
  *
  * @param integer|null $type
  * @return mixed
  */
 public function fetchAll($type = null, $class = null, array $classConstructor = array())
 {
     $this->verifyMySQLiErrorsAndThrowException();
     $results = array();
     switch ($type) {
         case null:
             if (is_null($this->standartFetchMode) || count($this->standartFetchMode) == 0 || !isset($this->standartFetchMode['type'])) {
                 while ($r = $this->result->fetch_array()) {
                     $results[] = $r;
                 }
             } else {
                 $results = isset($this->standartFetchMode['param2']) ? $this->fetchAll($this->standartFetchMode['type'], $this->standartFetchMode['param2'], $this->standartFetchMode['param3']) : $this->fetchAll($this->standartFetchMode['type']);
             }
             break;
         case Fetch::FETCH_BOTH:
             while ($r = $this->result->fetch_array()) {
                 $results[] = $r;
             }
             break;
         case Fetch::FETCH_OBJ:
             while ($r = $this->result->fetch_object()) {
                 $results[] = $r;
             }
             break;
         case Fetch::FETCH_ASSOC:
         case Fetch::FETCH_NAMED:
             while ($r = $this->result->fetch_assoc()) {
                 $results[] = $r;
             }
             break;
         case Fetch::FETCH_NUM:
             while ($r = $this->result->fetch_assoc()) {
                 $results[] = array_values($r);
             }
             break;
         case Fetch::FETCH_CLASS:
             while ($r = $this->result->fetch_assoc()) {
                 $results[] = $this->createObjectOfClassFromFetch($r, $class, $classConstructor);
             }
             break;
         default:
             StatementException::unknownFetchType($type);
     }
     return $results;
 }
 /**
  * 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;
 }