Skip to content

Commit

Permalink
Fetch_Into
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Dec 24, 2023
1 parent 1ec50db commit d097eb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions DataMapper/DataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ public function asClass(?string $class = null): self
/**
* @inheritDoc
*/
public function asObject(): self
public function asObject(?object $obj = null): self
{
$this->getStatement()->setFetchMode(PDO::FETCH_OBJ);
if (null !== $obj) {
$this->getStatement()->setFetchMode(PDO::FETCH_INTO, $obj);
} else {
$this->getStatement()->setFetchMode(PDO::FETCH_OBJ);
}

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion DataMapper/Interfaces/DataMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ public function numRows(): int;
public function asClass(?string $class = null): self;

/**
* @param null|object $obj
* @return self
* @throws DataMapperException
*/
public function asObject(): self;
public function asObject(?object $obj = null): self;

/**
* @return self
Expand Down

0 comments on commit d097eb0

Please sign in to comment.