Fetch the first field of the first row

@param	mysqli_result  	The result object. A result set identifier returned by the select() function
@param   integer         The index to use
@return The value returned in the query or null if the query failed.
174042
protected function _fetchField($result, $key = 0)
    {
        $return = null;
        if ($row = $result->fetch_row()) {
            $return = $row[(int)$key];
        }

        $result->free();

        return $return;
    }
1334384
public static function getRow($query)
    {
        $ret = null;

        $res = self::query($query);
        if ($res) {
            if ($row = self::connection()->sql_fetch_assoc($res)) {
                $ret = $row;
            }
            self::free($res);
        }

        return $ret;
    }
316122
public function first($result, $field = null)
    {
        $field = $this->prepareField($field ?: $result);

        $this->fields[$result] = ['$first' => $field];

        return $this;
    }
734979
public function first(): ?\stdClass
    {
        $pdoStatement = $this->provideStatement();
        $pdoStatement = $this->execute($pdoStatement);
        $row = $pdoStatement->fetch(\PDO::FETCH_OBJ);
        return (!empty($row)) ? $row : null;
    }
941761
public function fetchById($int_key_id)
    {
        $arr_results = $this->fetchByIds([$int_key_id]);
        if(count($arr_results) > 0) {
            return $arr_results[0];
        }
        return null;
    }
275790
protected function __getResult($result, string $index = null, bool $assoc = null){

		if(is_bool($result)){
			return $result;
		}

		$r = parent::getResult('sqlsrv_fetch_array', [$result, ($assoc ?? true) ? SQLSRV_FETCH_ASSOC : SQLSRV_FETCH_NUMERIC], $index, $assoc);

		sqlsrv_free_stmt($result);

		return $r;
	}
470493
public function offsetGet($index) {
		if( $this->results === null ){
			$this->results = ($this->query)();
		}
		if( isset($this->results[$index]) ){
			return $this->results[$index];
		}
		return null;
	}
277372
public function loadRow()
	{
		// Initialise variables
		$return = null;

		// Execute the query
		if (!$this->execute())
		{
			return null;
		}

		// Get the first row from the result set as an array
		if ($row = $this->fetchArray())
		{
			$return = $row;
		}

		// Free up system resources and return
		$this->freeResult();

		return $return;
	}
1239051
public function getResult($limit = 0, $offset = 0)
    {
        $this->count();
        $this->queryBuilder->setFirstResult($offset)->setMaxResults($limit);

        if ($limit > 0) {
            $pathOrderBy = $this->getSqlPart($this->queryBuilder, 'orderBy');
            $this->resetSqlParts($this->queryBuilder, ['orderBy']);
            $qb = $this->cloneQb($this->queryBuilder);
            $qb->select(sprintf('%s', $this->aliasDotPrimary()))
                ->setFirstResult(null)
                ->setMaxResults(null);

            /** @var OrderBy $part */
            foreach ($pathOrderBy as $part) {
                foreach ($part->getParts() as $order) {
                    $out = [];
                    preg_match('/(.*[^\s])?\s+(asc|desc)/i', $order, $out);
                    $property = $out[1];
                    $direction = $out[2];
                    $alias = ($key = array_search($property, $this->aliasMapping)) ?: $property;
                    if ($this->isAggFunc($property)) {
                        $qb->addSelect($property.' AS '.$alias);
                        $qb->addOrderBy($alias, $direction);
                        $this->queryBuilder->addOrderBy($alias, $direction);
                    } else {
                        $qb->addOrderBy($property, $direction);
                        $this->queryBuilder->addOrderBy($property, $direction);
                    }
                }
            }

            $query = $qb->getQuery();

            foreach ($this->hints as $name => $hint) {
                $query->setHint($name, $hint);
            }

            $params = $types = [];
            /** @var Parameter $parameter */
            foreach ($query->getParameters() as $key => $parameter) {
                $params[$key] = $parameter->getValue();
                $types[$key] = $parameter->getType();
            }

            /** @var \PDOStatement $stmt */
            $stmt = $this->queryBuilder->getEntityManager()->getConnection()->executeQuery(
                $query->getSQL(),
                $params,
                $types
            );

            $ids = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
            $ids = array_values(array_unique($ids));

            if (!$ids) {
                return [];
            }
            $ids = array_slice($ids, $offset, $limit);
            $this->queryBuilder
                ->setFirstResult(null)
                ->setMaxResults(null)
                ->where(sprintf("%s IN (:_sps_ids_)", $this->aliasDotPrimary()))
                ->setParameters(['_sps_ids_' => $ids]);
        }
        $query = $this->queryBuilder->getQuery();
        foreach ($this->hints as $name => $hint) {
            $query->setHint($name, $hint);
        }
        $this->result = $query->getResult();
        if (!$this->totalResultCount) {
            $this->totalResultCount = count($this->result);
        }

        return $this->result;
    }
614604
protected function getFirst($result = [])
    {

        if (array_key_exists("hits", $result) && count($result["hits"]["hits"])) {

            $data = $result["hits"]["hits"];

            if ($this->model) {
                $model = new $this->model($data[0]["_source"], true);
            } else {
                $model = new Model($data[0]["_source"], true);
                $model->setConnection($model->getConnection());
                $model->setIndex($data[0]["_index"]);
                $model->setType($data[0]["_type"]);
            }

            // match earlier version

            $model->_index = $data[0]["_index"];
            $model->_type = $data[0]["_type"];
            $model->_id = $data[0]["_id"];
            $model->_score = $data[0]["_score"];

            $new = $model;

        } else {
            $new = NULL;
        }

        return $new;
    }
553151
public function getRow($index = 0, $column = null)
    {
        //argument test
        Argument::i()
            //Argument 1 must be a string or int
            ->test(1, 'string', 'int')
            //Argument 2 must be a string or null
            ->test(2, 'string', 'null');
        
        if (is_string($index)) {
            $column = $index;
            $index = 0;
        }
        
        $rows = $this->getRows();
        
        if (!is_null($column) && isset($rows[$index][$column])) {
            return $rows[$index][$column];
        } else if (is_null($column) && isset($rows[$index])) {
            return $rows[$index];
        }
        
        return null;
    }
857341
protected function getFieldValue($field_name, array $results, $delimiter = '.')
    {
        // Progress the results if the field name is using a delimiter.
        foreach (explode($delimiter, $field_name) as $name) {
            if (isset($results[$name])) {
                $results = $results[$name];
            }
        }

        return !empty($results) ? $results : null;
    }
11201
function offsetGet($index)
    {
        if (isset($this->{$index})) {
            return $this->{$index};
        } else {
            $records = $this->records();
            if ($index === "results") {
                return $records;
            }
            if ($record =& $records[$index]) {
                return $record;
            }
            foreach ((array)$records as $key => $record) {
                if ($record['id'] === $index) {
                    $record =& $records[$key];
                    return $record;
                }
            }
        }

        return null;
    }
1329835
public function first()
    {
        $sql = clone($this);
        $sql->limit(1);
        $result = $this->_adapter->query($sql, $sql->getParameters());
        return  (count($result) > 0) ? $result[0]: null;
    }
1143462
public function loadResult()
	{
		// Initialise variables
		$return = null;

		// Execute the query
		if (!$this->execute())
		{
			return null;
		}

		// Get the first row from the result set as an array
		if ($row = $this->fetchArray())
		{
			$return = $row[0];
		}

		// Free up system resources and return
		$this->freeResult();

		return $return;
	}
1172328
public static function fetchOneValue(string $field, $where = null, $orderField = null, $orderDirection = null)
    {
        $select = static::select()->field($field, 'key_field')->limit(0, 1);

        if ($where !== null) {
            if ($where instanceof Where) {
                $select->where($where);
            } else if (is_array($where)) {
                foreach ($where as $field => $value) {
                    $select->where($field, $value);
                }
            } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
                $select->where(static::$primaryKey, $where);
            }
        }

        if ($orderField !== null) {
            $select->orderBy($orderField, $orderDirection);
        }

        $records = $select->fetchAll();
        if (count($records) == 0) {
            return null;
        }

        return $records[0]['key_field'];
    }
1297307
public function fetchRow()
    {
        $opts = $this->options;
        $opts['limit'] = 1;
        
        $sql = QueryBuilder::optionsToSql($opts);
        $row = $this->getDb()->getRow($sql);
        
        return $row;        
    }