Fetch an array of single field results


@param	mysqli_result  	The result object. A result set identifier returned by the select() function
@param   integer         The index to use
@return 	array 			A sequential array of returned rows.
519238
protected function _fetchFieldList($result, $key = 0)
    {
        $array = array();

        while ($row = $result->fetch_row()) {
            $array[] = $row[(int)$key];
        }

        $result->free();

        return $array;
    }
983691
public function getAll($fields = null, $sqlQuery = false)
    {
        $sql = $this->buildQuery('select', $fields);
        if($sqlQuery === true) {
            return $this->getQuery();
        }
        $result = $this->executeQuery($sql);
        if($result->num_rows == 0) {
            return [];
        }
        while($row = $result->fetch_array(MYSQLI_ASSOC)) {
            $data[] = $row;
        }
        return $data;
    }
110951
public function fetchColumn($index = 0): Generator
    {
        $offset = $this->getColumnIndex($index, __METHOD__.'() expects the column index to be a valid string or integer, `%s` given');
        $filter = static function (array $record) use ($offset): bool {
            return isset($record[$offset]);
        };

        $select = static function (array $record) use ($offset): string {
            return $record[$offset];
        };

        $iterator = new MapIterator(new CallbackFilterIterator($this->records, $filter), $select);
        foreach ($iterator as $offset => $value) {
            yield $offset => $value;
        }
    }
754989
public function query($sql, $options = [])
    {
        $resultMode = isset($options[self::RESULT_MODE_INDEX]) ? (int) $options[self::RESULT_MODE_INDEX] : MYSQLI_STORE_RESULT;
        /**
         * the RETURN_MODE_INDEX should contain one of the following constants http://php.net/manual/en/mysqli-result.fetch-all.php
         */
        $returnMode = isset($options[self::RESULT_RETURN_MODE_INDEX]) ? (int) $options[self::RESULT_RETURN_MODE_INDEX] : MYSQLI_BOTH;
        try {
            /**
             * @var \mysqli_result $result
             */
            $result = $this->getResource()->query($sql, $resultMode);
            switch($options[self::RESULT_TYPE_INDEX])
            {
                case self::RESULT_TYPE_GENERATOR:
                    return $this->rowGenerator($result, $returnMode);
                    break;

                case self::RESULT_TYPE_NUM_ARRAY:
                case self::RESULT_TYPE_ASSOC_ARRAY;
                    return $result->fetch_all($returnMode);
                    break;

                case self::RESULT_TYPE_ITERATOR:
                    return new \ArrayIterator($result->fetch_all($returnMode));
                    break;

                case self::RESULT_TYPE_OBJECT_ARRAY:
                    $gen = $this->rowGenerator($result, $returnMode);
                    $result = [];
                    foreach ($gen as $row) {
                        $result[] = $row;
                    }
                    return $result;

                default:
                    return $this->getResult()->fetch_all();
                    break;
            }
        } catch (\mysqli_sql_exception $e) {
            return false;
        }
    }
864328
protected function fetchResult(Select $select, AbstractResultSet $resultSet = null)
    {
        $resultSet = $resultSet ?: $this->getResultSet();
        $resultSet->buffer();

        if ($this->usePaginator()) {
            $this->setUsePaginator(false);
            $resultSet = $this->paginate($select, $resultSet);
        } else {
            $statement = $this->getSql()->prepareStatementForSqlObject($select);
            $result = $statement->execute();
            $resultSet->initialize($result);
        }

        return $resultSet;
    }
999074
protected function fetch($sql)
    {
        try {
            try {
                $stm = Connect::getConn()->prepare($sql);
            } catch (Exception $e) {
                static::$response["status"] = "error";
                static::$response["response"] = $e->getMessage();
                static::$response['code'] = $e->getCode();
               return static::terminate(static::$response);

            }
            try {
                $stm->execute();
            } catch (Exception $e) {
                static::$response["status"] = "error";
                static::$response["response"] = $e->getMessage();
                static::$response['code'] = $e->getCode();
               return static::terminate(static::$response);
            }
        } catch (Exception $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response['code'] = $e->getCode();
           return static::terminate(static::$response);

        }
        try {
            $data = null;
            // set the resulting array to associative
            $stm->setFetchMode(PDO::FETCH_ASSOC);
            foreach (new RecursiveArrayIterator($stm->fetchAll()) as $k => $v) {
                $data[] = $v;
            }

            if ($data == null) {
                static::$response["status"] = "success";
                static::$response["response"] = Null;
                static::$response['code'] = 300;
               return static::terminate(static::$response);
            }
            static::$response["status"] = "success";
            static::$response["response"] = $data;
            static::$response['code'] = 200;
            return static::terminate(static::$response);


        } catch (PDOException $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response["code"] = $e->getCode();
           return static::terminate(static::$response);
        }


    }
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;
	}
1313189
function multi_query($sql)
    {
        $result = $this->tryReconnect(array('parent', 'multi_query'), array($sql));
        if (!$result)
        {
            Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
            return false;
        }

        $result = call_user_func_array(array('parent', 'use_result'), array());
        $output = array();
        while ($row = $result->fetch_assoc())
        {
            $output[] = $row;
        }
        $result->free();

        while (call_user_func_array(array('parent', 'more_results'), array()) && call_user_func_array(array(
                'parent',
                'next_result'
            ), array()))
        {
            $extraResult = call_user_func_array(array('parent', 'use_result'), array());
            if ($extraResult instanceof \mysqli_result)
            {
                $extraResult->free();
            }
        }

        return $output;
    }
760090
public static function multi_query($sql) {
        self::init();
        self::connect();
        mysqli_report(MYSQLI_REPORT_STRICT);
        try {
            $query = self::connect()->multi_query($sql);
        } catch(mysqli_sql_exception $e) {
            throw $e;
        }
        return ['result' => $query, 'link' => self::$_db];
    }
687040
public function loadResult($index = 0)
    {
        if ($this->stmt === null) {
            return null;
        }

        $singleResult = $this->stmt->fetch(\PDO::FETCH_NUM);
        return $singleResult[$index];
    }
1354420
protected function extractResult()
    {
        if (!$this->getQuery()) {
            throw new \Exception(sprintf(
                'No defined query from %s. Did you forget to call method %s ?',
                Query::class,
                '"setQuery()"'
            ));
            exit;
        }

        $arrayResult = $this->getArrayResult();

        if (isset($arrayResult['error']) && isset($arrayResult['message']) && $arrayResult['error'] === true) {
            $this->getQuery()->getError()->setMessage($arrayResult['message']);
        } elseif (isset($arrayResult['response']) && $arrayResult['response']) {
            $response = $arrayResult['response'];
            $resultDataType = $this->getQuery()->getResultDataType();

            foreach ($response as $index => $result) {
                $sql = $this->getQuery()->addOrReplace($index, $result['string']);
                $sqlResult = $sql->getResult();

                if ($resultDataType instanceof DataInterface) {
                    $sqlResult->setDataType($resultDataType);
                }

                $sql->execute($result['executed']);
                $insertId = $result['result']['insertId'];

                $sqlResult->setColumnTypes($result['result']['types']);
                $sqlResult->setStart($result['result']['start']);
                $sqlResult->setEnd($result['result']['end']);
                $sqlResult->setAffected($result['result']['affected']);
                $sqlResult->setStartRow($result['result']['startRow']);
                $sqlResult->setTotalRows($result['result']['totalRows']);
                $sqlResult->setTotalShows($result['result']['totalShows']);
                $sqlResult->setInsertId(is_numeric($insertId) ? floatval($insertId) : $insertId);

                foreach ($result['result']['data'] as $data) {
                    if (!is_array($sqlResult->getDataType())) {
                        $item = $sqlResult->getDataType();
                        foreach ($data as $key => $value) {
                            $item->set($key, $value);
                        }
                        $data = $item;
                    }
                    $sqlResult->add($data);
                }
            }

            $this->getQuery()->removeFromIndex(count($response));
        }

        return $this->getQuery();
    }
922873
public function getResult($limit = 0, $offset = 0)
    {
        if ($limit > 0 && false === $this->limitOffset($limit, $offset)) {
            return [];
        }

        $stmt = $this->queryBuilder->execute();
        $this->result = $stmt->fetchAll();

        return $this->result;
    }
648371
public function fetch()
    {
        
        if ((null !== $this->statement) && $this->statement->fetch()) {
            $row = [];
            foreach ($this->stmt_results as $dbColumnName => $dbColumnValue) {
                $row[$this->stmt_cols[$dbColumnName]] = $dbColumnValue;
            }
            return $row;
        } elseif ($this->result instanceof \mysqli_result) {
            return mysqli_fetch_array($this->result, MYSQLI_ASSOC);
        } else {
            return null;
            
            if (!isset($this->result)) {
                throw new Exception('The database result resource is not currently set.');
            }
        }
    }
196175
public function getResult($index = 0)
    {
        if($index == 0 && count($this->results) > 0)
            return current($this->results);

        return isset($this->results[$index]) ?
                    $this->results[$index]
                : null;
    }
538127
public function fetch($return = self::RETURN_COLLECTION) {
        /** We replace Post.xx by post.xx */
        foreach ($this->_entities as $entity) {
            $class = $this->_getTableEntity($entity);

            if ($entity != $class->name()) {
                $this->_query = preg_replace('#(.*)' . $entity . '\.(.*)#isU', '$1' . $class->name() . '.$2', $this->_query);
            }
        }

        /** Query execution */
        $sql = new Sql();
        $sql->vars($this->_vars);
        $sql->query('orm-' . $this->_token, $this->_query);

        if ($this->_type == self::QUERY_COUNT) {
            return $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCHCOLUMN);
        }
        else {
            $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCH);
        }

        $collection = $sql->data($this->_getEntityName($this->_entity->name()));

        /** We can do SELECT OR SELECT DISTINCT OR SELECT RAW */
        if (in_array($this->_type, [self::QUERY_DISTINCT, self::QUERY_RAW])) {
            $nLines = $collection->count();
            $in = '';

            /** @var $value \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($collection as $key => $value) {
                $in .= $value->fields()[$value->primary()]->value;

                if ($key < $nLines - 1) {
                    $in .= ', ';
                }
            }

            $builder = new Builder($this->_entity);
            $collection = $builder->find()->where($this->_entity->name() . '.' . $this->_entity->primary() . ' IN (' . $in . ')')->fetch();
        }

        /** If we have fields with a relation ONE TO MANY OR MANY TO MANY */
        foreach ($this->_entity->fields() as $field) {
            if ($field->foreign != null && in_array($field->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                /** we loop through the results to add each time */
                switch ($field->foreign->type()) {
                    case ForeignKey::ONE_TO_MANY :
                        $collection = $this->_dataOneToMany($field, $collection);
                        break;

                    case ForeignKey::MANY_TO_MANY :
                        $collection = $this->_dataManyToMany($field, $collection);
                        break;
                }
            }
        }

        if ($return == self::RETURN_ENTITY && $collection->count() <= 1) {
            return $collection->first();
        }
        else {
            return $collection;
        }
    }
855802
public static function fetch($tables)
    {
        foreach ($tables as $table) {
            $result = Driver::query("SELECT * FROM $table", Driver::INDEX);
            $fields = $result->columnCount();
            $rows = $result->rowCount();
            $data = Driver::read("SELECT * FROM $table", Driver::INDEX);
            //
            $content = (!isset($content) ? '' : $content).self::stucture($table);
            //

            $st_counter = 0;
            foreach ($data as $row) {
                if ($st_counter % 100 == 0 || $st_counter == 0) {
                    $content .= "\n-- Table Data\nINSERT INTO ".$table.' VALUES';
                }
                //
                $content .= "\n(";
                //
                for ($j = 0; $j < $fields; $j++) {
                    $row[$j] = str_replace("\n", '\\n', addslashes($row[$j]));
                    //
                    if (isset($row[$j])) {
                        if (!empty($row[$j])) {
                            $content .= '"'.$row[$j].'"';
                        } else {
                            $content .= 'NULL';
                        }
                    }
                    //
                    else {
                        $content .= '""';
                    }
                    //
                    if ($j < ($fields - 1)) {
                        $content .= ',';
                    }
                }
                //
                $content .= ')';
                //
                if ((($st_counter + 1) % 100 == 0 && $st_counter != 0) || $st_counter + 1 == $rows) {
                    $content .= ';';
                }
                //
                else {
                    $content .= ',';
                }
                //
                $st_counter = $st_counter + 1;
            }

            $content .= "\n\n\n";
        }

        return $content;
    }
1180925
public function fetchResults()
    {
        if (count($this->results) == 0) {
            while ($result = $this->fetchResult()) {
                $this->results[] = $result;
            }
        }

        return $this->results;
    }