Query fetcher

@param  string  $q        Query
@param  boolean $fetchAll fetchAll or fetch
@return object  PDO
326727
private function query($q, $fetchAll = true)
    {
        $stmt = $this->dbh->query($q);

        if ($fetchAll === true)
        {
            return $stmt->fetchAll();
        }
        else
        {
            return $stmt->fetch();
        }
    }
975738
static public function findByQuery($sqlQuery, array $params, $fetchMode = \PDO::FETCH_OBJ)
    {
        $model = new static;
        if($model->table) {
            $sqlQuery = str_replace(':table', $model->table, $sqlQuery);
        }

        $result = $model->execute($sqlQuery);
        return $result;
    }
1111232
private function fetch($getData=true) {
      try{
         $this->connection();
         $this->resultset = $this->id_conn->prepare($this->sql);
         $this->resultset->execute($this->placeholder_data);
         $this->resultset->setFetchMode( $this->{'FETCH_' . strtoupper( $this->type_fetch )} );
         if ( $getData ) {
            $this->rows     = $this->resultset->fetchAll();
            $this->rowCount = $this->resultset->rowCount();
            // while ( $row = $this->resultset->fetch() ) {
            //    $this->rows[] = $row;
            //    $this->rowCount++;
            // }
         }

         $this->get_instance();
      } catch (\PDOException $e) {
         die("Error: " . $e->getMessage() . "<br/>");
      }

      return $this;
   }
980872
public final function fetchAll($sql, array $bind = [])
    {
        return $this->query($sql, $bind)->fetchAll(\PDO::FETCH_NAMED);
    }
472384
protected function _fetch() {
		if (!$this->_resource instanceof PDOStatement) {
			$this->close();
			return false;
		}
		try {
			if ($result = $this->_resource->fetch(PDO::FETCH_NUM)) {
				return [$this->_iterator++, $result];
			}
		} catch (PDOException $e) {
			$this->close();
			return false;
		}
		return null;
	}
723757
public function fetchAll(int $fetchStyle = \PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = array()): array
    {
        if(!is_array($this->data))
        {
            return [];
        }
        return $this->fetchAllParser->parseAll($this->data, $fetchStyle, $fetchArgument, $ctorArgs);
    }
96065
private function fetch($multi, $array = false)
    {
        // Let the generator do his work now,
        if ($this->queryType !== self::QUERY_SELECT) {
            throw new QueryException("Can only do all() or one() on SELECT mode!", 0, $this->exception);
        }

        $this->bindValues = array();
        $this->bindTypes = array();

        // Join
        $this->generator->generateJoin($this->joinTables, $this->join);

        // Where
        $this->generator->generateWhere($this->whereConditions, $this->where, $this->bindValues, $this->bindTypes);

        // Order
        $this->generator->generateOrder($this->sortBy, $this->sortOrder, $this->order);

        // Limit
        $this->generator->generateLimit($this->limitCount, $this->limitOffset, $this->limit);


        // Combine parts
        $this->query = "";
        $this->combineQuery();

        // Get connection and prepare
        $connection = ConnectionManager::getConnection();
        $query = $connection->prepare($this->query);

        // Bind all values
        $idx = 1;
        foreach ($this->bindValues as $key => $value) {
            $query->bindValue($idx, $value, $this->bindTypes[$key]);
            $idx++;
        }

        // Set fetch mode
        if (! $array)
            $query->setFetchMode(\PDO::FETCH_CLASS, $this->class);
        else
            $query->setFetchMode(\PDO::FETCH_ASSOC);

        // Execute
        $query->execute();

        // Fetch and return
        $result = null;
        if ($multi)
            $result = $query->fetchAll();
        else
            $result = $query->fetch();
        if ($array) return $result;
        return $this->injectState($result);
    }
317985
public function fetch(
        $fetch_style = PDO::FETCH_BOTH,
        $cursor_orientation = PDO::FETCH_ORI_NEXT,
        $cursor_offset = 0
    )
    {
        static $styleUnsupport = [
            'PDO::FETCH_BOUND' => PDO::FETCH_BOUND,
            'PDO::FETCH_CLASS' => PDO::FETCH_CLASS,
            'PDO::FETCH_INTO' => PDO::FETCH_INTO,
            'PDO::FETCH_LAZY' => PDO::FETCH_LAZY,
            'PDO::FETCH_NAMED' => PDO::FETCH_NAMED,
            'PDO::FETCH_OBJ' => PDO::FETCH_OBJ,
        ];
        if ($cursor_orientation !== PDO::FETCH_ORI_NEXT || $cursor_offset !== 0) {
            throw new PDOException('$cursor_orientation that is not PDO::FETCH_ORI_NEXT is not implemented for PoolPDOStatement::fetch()');
        }
        if(in_array($fetch_style,$styleUnsupport)) {
            throw new PDOException(array_search($fetch_style,$styleUnsupport).'is not implemented for PoolPDOStatement::fetch()');
        }

        if(
            empty($this->_resultData)
            || empty($result = $this->_resultData->result)
            || empty($data = $result[$this->_index++] ?? [])
        ){
            return false;
        }

        if($fetch_style == PDO::FETCH_NUM){
            $data = array_values($data);
        }elseif ($fetch_style == PDO::FETCH_BOTH){
            $dataRows = array_values($data);
            $data = array_merge($data,$dataRows);
        }

        return $data;
    }
898674
public static function _queryToObjects ($query, $key = FALSE)
	{
		$query->execute ();
		return static::_arrayToObjects ($query->fetchAll (\PDO::FETCH_ASSOC), $key);
	}
556245
public function fetchAll($query, array $parameters = array(), $fetchMode = null)
    {
        $parameters = $this->parameterTransformer->transform($parameters);

        $this->stopWatch->start('query', 'database');
        $result = $this->reader->fetchAll($query, $parameters, $fetchMode);
        $event = $this->stopWatch->stop('query');

        $this->log($query, $parameters, $event, 'fetch', 'all');

        return $result;
    }
1178373
public function fetchAll($sql, $bind = [], $fetchMode = \PDO::FETCH_ASSOC, $useMaster = false)
    {
        $context = $this->_context;

        $context->sql = $sql;
        $context->bind = $bind;
        $context->affected_rows = 0;

        $this->eventsManager->fireEvent('db:beforeQuery', $this);

        if ($context->connection) {
            $type = null;
            $connection = $context->connection;
        } else {
            $type = $this->_has_slave ? 'slave' : 'default';
            $connection = $this->poolManager->pop($this, $this->_timeout, $type);
        }

        try {
            $start_time = microtime(true);
            $result = $connection->query($sql, $bind, $fetchMode, $useMaster);
            $elapsed = round(microtime(true) - $start_time, 3);
        } finally {
            if ($type) {
                $this->poolManager->push($this, $connection, $type);
            }
        }

        $count = $context->affected_rows = count($result);

        $event_data = compact('elapsed', 'count', 'sql', 'bind', 'result');

        $this->logger->debug($event_data, 'db.query');

        $this->eventsManager->fireEvent('db:afterQuery', $this, $event_data);

        return $result;
    }
1155197
public function fetchAll($fetchType = 'assoc')
    {
        if ($fetchType === 'num') {
            return $this->statement->fetchAll(\PDO::FETCH_NUM);
        } elseif ($fetchType === 'assoc') {
            return $this->statement->fetchAll(\PDO::FETCH_ASSOC);
        } elseif ($fetchType === 'obj') {
            return $this->statement->fetchAll(\PDO::FETCH_OBJ);
        }
    }
1237230
public final function get(string $query, array $queryParams = null, string $fetchClass = null)
    {
        return $this->query($query, $queryParams, 1, $fetchClass)->getData(0);
    }
369742
public function query($statement, ...$fetch)
    {
        $this->connect();

        // trigger before event
        $this->fire(self::BEFORE_EXECUTE, [$statement, 'query']);

        $sth = $this->pdo->query($this->replaceTablePrefix($statement), ...$fetch);

        // trigger after event
        $this->fire(self::AFTER_EXECUTE, [$statement, 'query']);

        return $sth;
    }
7116
public function fetch(int $fetchStyle = \PDO::FETCH_ASSOC, int $cursorOrientation = \PDO::FETCH_ORI_NEXT, int $cursorOffset = 0)
    {
        return $this->statement->fetch($fetchStyle, $cursorOrientation, $cursorOffset);
    }
27070
public function query ($sql, array $bound_parameters = array(), $fetch = true) {

		$statement = $this -> entity_manager -> getConnection() -> prepare($sql);

		foreach ($bound_parameters as $parameter => $value) {
			$statement -> bindValue($parameter, $value);
		}

		$statement -> execute();

		if ($fetch) {
			return $statement -> fetchAll();
		} else {
			return null;
		}
	}
969074
public function fetchAll($fetch_style = null, $fetch_argument = null, $ctor_args = null)
    {
        if ($fetch_style === null) {
            return parent::fetchAll();
        }

        if ($fetch_argument === null) {
            return parent::fetchAll($fetch_style);
        }

        if ($ctor_args === null) {
            return parent::fetchAll($fetch_style, $fetch_argument);
        }

        return parent::fetchAll($fetch_style, $fetch_argument, $ctor_args);
    }