public function hydrate(Statement $statement) { $rows = $statement->fetchAll(PDO::FETCH_ASSOC); if (!$rows) { return array(); } if ($this->normalize) { foreach ($rows as $key => $row) { $rows[$key] = $statement->normalizeRow($row); } } $keys = array_keys((array) reset($rows)); if (!count($keys)) { throw new \LogicException('Result set does not contain any column.'); } elseif ($this->key === NULL && $this->value === NULL) { if (count($keys) === 1) { list($this->value) = $keys; } else { list($this->key, $this->value) = $keys; } } $return = array(); if ($this->key === NULL) { foreach ($rows as $row) { $return[] = $this->value === NULL ? $row : $row[$this->value]; } } else { foreach ($rows as $row) { $return[is_object($row[$this->key]) ? (string) $row[$this->key] : $row[$this->key]] = $this->value === NULL ? $row : $row[$this->value]; } } return $return; }
public function hydrate(Statement $statement) { $res = $statement->fetchAll(PDO::FETCH_ASSOC); if (false !== $res) { if ($this->normalize) { foreach ($res as $key => $row) { $res[$key] = ArrayHash::from($statement->normalizeRow($row)); } } else { foreach ($res as $key => $row) { $res[$key] = ArrayHash::from($row); } } } return $res; }
public function hydrate(Statement $statement) { $columnIndex = $this->columnIndex; if (is_string($columnIndex)) { $columnCount = $statement->getColumnCount(); for ($i = 0; $i < $columnCount; $i++) { $meta = $statement->getColumnMeta($i); if ($meta['name'] == $columnIndex) { $columnIndex = $i; break; } } } $res = $statement->fetchAll(PDO::FETCH_COLUMN, $columnIndex); if ($res !== false && $this->normalize) { foreach ($res as $key => $value) { $value = $statement->normalizeRow(array($columnIndex => $value)); $res[$key] = $value[$columnIndex]; } } return $res; }