From d097eb0857b05e6cc4119f5258742f96f4c8d286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammet=20=C5=9EAFAK?= Date: Sun, 24 Dec 2023 06:25:41 +0300 Subject: [PATCH] Fetch_Into --- DataMapper/DataMapper.php | 8 ++++++-- DataMapper/Interfaces/DataMapperInterface.php | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/DataMapper/DataMapper.php b/DataMapper/DataMapper.php index 591860d..8f2c5b1 100644 --- a/DataMapper/DataMapper.php +++ b/DataMapper/DataMapper.php @@ -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; } diff --git a/DataMapper/Interfaces/DataMapperInterface.php b/DataMapper/Interfaces/DataMapperInterface.php index 3bb1189..1571c88 100644 --- a/DataMapper/Interfaces/DataMapperInterface.php +++ b/DataMapper/Interfaces/DataMapperInterface.php @@ -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