public function query($query, $return_set = false, $buffered = true){

		$this->_result = null;

		$query = trim($query);

		$this->_result = @mysqli_query($this->_connection, $query);

		// Invalid Query

		if(!$this->_result){

			$error_no = @mysqli_errno($this->_connection); //NOSONAR
			$error_message = @mysqli_error($this->_connection); //NOSONAR

			if(empty($error_message)){

				throw new ConnectionException('An unknown error occurred while
					attempting to query the MySQL server');
			}
			else{

				switch($error_no){

					case static::ER_LOCK_WAIT_TIMEOUT:

						throw new SQLUnavailableException("Invalid Query,
							MySQL returned error {$error_no}: {$error_message}");

					break;

					default:

						throw new QueryException("Invalid Query,
							MySQL returned error {$error_no}: {$error_message}");

					break;
				}
			}
		}

		// Valid Query

		else{

			$num_rows = @mysqli_num_rows($this->_result);
			$matches = [];

			/** @noinspection PhpUnusedLocalVariableInspection */
			$match_count = preg_match(
				'/^([\w]+)(?:[\W]+|$)/i', $query, $matches);
			assert('$match_count === 1');

			$query_type = strtoupper($matches[1]);

			switch($query_type){

				case 'SELECT':
				case 'SHOW':
				case 'EXPLAIN':
				case 'DESCRIBE':

					if($return_set && $num_rows >= 1){

						return new MySQLResultSet($this->_result, $buffered);
					}
					elseif($num_rows == 1){

						return new MySQLResultRow($this->_result);
					}
					elseif($num_rows > 1){

						return new MySQLResultSet($this->_result, $buffered);
					}
					else{

						return false;
					}

				break;

				case 'DELETE':
				case 'INSERT':
				case 'REPLACE':
				case 'UPDATE':

					return $this->getAffectedRows();

				break;

				case 'START':
				case 'COMMIT':
				case 'ROLLBACK':
				case 'SET':

					return true;

				break;

				default:

					return false;
			}
		}
	}