Fetch a record from the storage

@param string $query
@param array $data
@return object data as object
16965
public function findOne($query, array $data = null) {       
        $stmt = $this->executeQuery($query, $data);   
        
        return $stmt->fetch(\PDO::FETCH_ASSOC);
    }
1159848
protected function parseData(Query $query, $data)
    {
        if (empty($data)) {
            return [];
        }

        $result = [];

        foreach ($data as $key => $val) {
            $item = $this->parseKey($key);

            if (is_object($val)) {
                $result[$item] = $val;
            } elseif (isset($val[0]) && 'exp' === $val[0]) {
                $result[$item] = $val[1];
            } elseif (is_null($val)) {
                $result[$item] = 'NULL';
            } else {
                $result[$item] = $this->parseValue($query, $val, $key);
            }
        }

        return $result;
    }
159331
public function fetchOne($query, array $parameters = array())
    {
        $parameters = $this->parameterTransformer->transform($parameters);

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

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

        return $result;
    }
1229913
public function getObject($query, $object)
    {
        $this->statement = $this->db->query($query);
        if ($this->statement) {
            $this->statement->setFetchMode(\PDO::FETCH_CLASS, $object);
            return $this->statement->fetch();
        }
        return false;
    }
1172785
public static function query($query)
    {
        //
        static::applySchema();

        //
        $table = self::getTable();
        $whereArray = [];

        //
        if (isset($query['where'])) {
            $whereArray[] = '('.$query['where'].')';
            unset($query['where']);
        }

        //
        foreach ($query as $field => $value) {
            if (in_array($field, ['order', 'limit'])) {
                continue;
            }
            $whereArray[] = "{$field} = '{$value}'";
        }

        //
        $where = count($whereArray) > 0 ? 'WHERE '.implode(' AND ', $whereArray) : '';
        $order = isset($query['order']) ? 'ORDER BY '.$query['order'] : '';
        $limit = isset($query['limit']) ? 'LIMIT '.$query['limit'] : '';
        $sql = "SELECT * FROM {$table} {$where} {$order} {$limit}";
        $results = static::getDatabase()->getResults($sql);

        //
        foreach ($results as &$record) {
            $record = static::create($record);
        }

        return $results;
    }
271226
public function setQuery($query)
    {
        if (!empty($query)) {
            $this->data['query'] = $this->_queryToArray($query);
        }

        return $this;
    }
249268
public function prepare($query = null)
    {
        $of         = is_null($query) ? $this->getQuery() : $query;
        $datatables = $this->datatables->of($of, get_class($this));
        $path       = str_replace(url('/'), '', url()->current());
        Event::fire("datatables.value.{$path}", [$datatables]);
        Event::fire(new Value($path, $datatables));

        return $datatables;
    }
29570
public function queryFromFilter(Query $query, array $data = [])
    {
        $query = parent::queryFromFilter($query, $data);

        //"Username" field
        if (!empty($data['username']) && strlen($data['username']) > 2) {
            $query->where([sprintf('%s.username LIKE', $this->getAlias()) => sprintf('%%%s%%', $data['username'])]);
        }

        //"Group" field
        if (!empty($data['group']) && is_positive($data['group'])) {
            $query->where([sprintf('%s.group_id', $this->getAlias()) => $data['group']]);
        }

        //"Status" field
        if (!empty($data['status'])) {
            switch ($data['status']) {
                case 'active':
                    $query->where([
                        sprintf('%s.active', $this->getAlias()) => true,
                        sprintf('%s.banned', $this->getAlias()) => false,
                    ]);

                    break;
                case 'pending':
                    $query->where([sprintf('%s.active', $this->getAlias()) => false]);

                    break;
                case 'banned':
                    $query->where([sprintf('%s.banned', $this->getAlias()) => true]);

                    break;
            }
        }

        return $query;
    }
820226
public function query($query = '', $params = null, $fetchmode = PDO::FETCH_ASSOC)
    {
        $query = trim($query);
        if (empty($query)) {
            $query = $this->build();
            if (!$params) {
                $params = $this->getBindValues();
            }
        }

        $this->resetAll();
        $this->lastSql = $query;

        $this->execute($query, $params);

        $rawStatement = explode(" ", $query);

        $statement = strtolower(trim($rawStatement[0]));
        if ($statement === 'select' || $statement === 'show') {
            return $this->sQuery->fetchAll($fetchmode);
        } elseif ($statement === 'update' || $statement === 'delete') {
            return $this->sQuery->rowCount();
        } elseif ($statement === 'insert') {
            if ($this->sQuery->rowCount() > 0) {
                return $this->lastInsertId();
            }
        } else {
            return null;
        }

        return null;
    }
1077310
function queryData($query, $keyField=null, $resultType = MYSQLI_ASSOC)
  {
    $data = [];
    $res = $this->q($query);
    if ($keyField == null)
      $data = $res->fetch_all($resultType);
    else while ($row = $res->fetch_array($resultType))
    {
      if ($keyField)
        $data[$row[$keyField]] = $row;
    }
    $res->close();
    return $data;
  }
820065
public function query($query)
    {
        $statement = $this->db->prepare($query);
        $statement->execute($this->binds);

        $this->clear();

        $collection = array();

        while (false !== ($row = $statement->fetchObject())) {
            $collection[] = $this->newDataInstance($row, true);
        }

        return $collection;
    }
933500
public function fetch($query, $values = null)
  {
    $m  = $this->getManager();
    $st = $m->query($query, $values);

    /** @var $collection Collection */
    $class = $this->getCollectionClass();
    $collection = new $class;
    while ($obj = $this->fetchObject($st)) {
      if ($pk = $obj->getPrimaryKey()) {
        $collection->set($obj->get($pk), $obj);
      } else {
        $collection->add($obj);
      }
    }

    return $collection;
  }
357934
protected function fetch($db, $query, array $args = [])
    {
        $stmt = $this->prepareStatement($db, $query);

        foreach ($args as $arg => $val) {
            $stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
        }
        $stmt->execute();

        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
659645
public function query($query, ...$data)
    {
        if ($data) {
            $query = $this->merge($query, $data);
        }

        try {
            $statement = $this->pdo->query($query);

            return new Result($statement);
        } catch (PDOException $exception) {
            throw new QueryException($exception, $query);
        }
    }
735130
public function executeAndFetchArray($query, $parameters = [])
    {
        $statement = $this->link->prepare($query);

        $statement->execute($parameters);
        $data = $statement->fetch(PDO::FETCH_COLUMN);
        $statement->closeCursor();

        return $data;
    }
1082077
public static function find(array $query)
    {
        $pubs = Client::get('publication', $query);
        return array_map(function ($data) { return new self($data); }, $pubs);
    }
93662
private function sendQuery($query, array $data = null) {
        if (!is_null($data)) {
            $Template = new QueryTemplate();
            $Template->load($query);
            pg_send_query($this->Resource, $Template->parse($data));
        } else {
            pg_send_query($this->Resource, $query);
        }
    }