Basecoat\DB::fetchAll PHP Метод

fetchAll() публичный Метод

Fetch all rows from the database after SELECT query is run Rows can be fetched with a field as the index instead of sequential index By specifying a $keyField and $grouped, record will be returned grouped by the key field
public fetchAll ( variable &$resultVar, string $keyField = null, boolean $grouped = false, boolean $useMaster = false, constant $method = null ) : integer
$resultVar variable variable reference to store the result in
$keyField string field to use as the array key
$grouped boolean if $keyField specified, group by the key field
$useMaster boolean set to TRUE to use the master server connection
$method constant PDO method to use for fetch records (default is PDO::FETCH_ASSOC)
Результат integer 1 if successful, -1 if error. Fetched data is stored in $selectResult class variable by default
    public function fetchAll(&$resultVar, $keyField = null, $grouped = false, $useMaster = false, $method = null)
    {
        if ($useMaster) {
            $sth =& self::$msth;
        } else {
            $sth =& $this->sth;
        }
        if (!is_object($sth)) {
            $this->errorCode = 'n/a';
            $this->errorMsg = 'Statement handle is not an object.';
            return -1;
        }
        if (is_null($method)) {
            $method = \PDO::FETCH_ASSOC;
        }
        $resultVar = array();
        if (is_null($keyField)) {
            $st = round(microtime(true), 3);
            $resultVar = $sth->fetchAll($method);
        } elseif ($grouped) {
            while ($row = $sth->fetch($method)) {
                $resultVar[$row[$keyField]][] = $row;
            }
        } else {
            while ($row = $sth->fetch($method)) {
                $resultVar[$row[$keyField]] = $row;
            }
        }
        return 1;
    }