Zebra_Database::fetch_assoc_all PHP Method

fetch_assoc_all() public method

run a query $db->query('SELECT * FROM table WHERE criteria = ?', array($criteria)); fetch all the rows as an associative array $records = $db->fetch_assoc_all();
public fetch_assoc_all ( string $index = '', resource $resource = '' ) : mixed
$index string (Optional) Name of a column containing unique values. If specified, the returned associative array's keys will be the values from this column. If not specified, returned array will have numerical indexes, starting from 0. @param resource $resource (Optional) Resource to fetch. If not specified, the resource returned by the last run query is used. @since 1.1.2 @return mixed Returns an associative array containing all the rows from the resource created by the previous query or from the resource given as argument and moves the internal pointer to the end. Returns FALSE on error.
$resource resource
return mixed
    function fetch_assoc_all($index = '', $resource = '')
    {
        // if an active connection exists
        if ($this->_connected()) {
            // if no resource was specified, and a query was run before, assign the last resource
            if ($resource == '' && isset($this->last_result)) {
                $resource =& $this->last_result;
            }
            if ($this->_is_result($resource) || is_integer($resource) && isset($this->cached_results[$resource])) {
                // this is the array that will contain the results
                $result = array();
                // move the pointer to the start of $resource
                // if there are any rows available (notice the @)
                if (@$this->seek(0, $resource)) {
                    // iterate through the records
                    while ($row = $this->fetch_assoc($resource)) {
                        // if $index was specified and exists in the returned row, add data to the result
                        if (trim($index) != '' && isset($row[$index])) {
                            $result[$row[$index]] = $row;
                        } else {
                            $result[] = $row;
                        }
                    }
                }
                // return the results
                return $result;
                // if $resource is invalid
            } else {
                // save debug information
                $this->_log('errors', array('message' => $this->language['not_a_valid_resource']));
            }
        }
        // we don't have to report any error as either the _connected() method already did
        // or did so the checking for valid resource
        return false;
    }