Skip to content

Commit d097eb0

Browse files
committed
Fetch_Into
1 parent 1ec50db commit d097eb0

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

DataMapper/DataMapper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ public function asClass(?string $class = null): self
148148
/**
149149
* @inheritDoc
150150
*/
151-
public function asObject(): self
151+
public function asObject(?object $obj = null): self
152152
{
153-
$this->getStatement()->setFetchMode(PDO::FETCH_OBJ);
153+
if (null !== $obj) {
154+
$this->getStatement()->setFetchMode(PDO::FETCH_INTO, $obj);
155+
} else {
156+
$this->getStatement()->setFetchMode(PDO::FETCH_OBJ);
157+
}
154158

155159
return $this;
156160
}

DataMapper/Interfaces/DataMapperInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ public function numRows(): int;
8282
public function asClass(?string $class = null): self;
8383

8484
/**
85+
* @param null|object $obj
8586
* @return self
8687
* @throws DataMapperException
8788
*/
88-
public function asObject(): self;
89+
public function asObject(?object $obj = null): self;
8990

9091
/**
9192
* @return self

0 commit comments

Comments
 (0)