/** * @param string $statement * @return PdoStatement */ public function query($statement) { if ($this->mockedQueries->exists($statement)) { $result = $this->mockedQueries->getResult($statement); if ($result) { $this->queryLog->addQuery($statement); $statement = new PdoStatement(); $statement->setResult($result); return $statement; } } }
protected function buildFromPdoStatementLogic(\PdoStatement $statement, callable $callback = null) { $collection = $this->getCollection(); $statement->execute(); while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { $model = new $this->modelClass($this->container); if (!$model instanceof ModelInterface) { throw new \LogicException("The abstract factory only supports models which implement ModelInterface and have a hydrate method"); } $model->setExistsInDatabase(true); if (!is_null($callback)) { $model = call_user_func_array($callback, array($model, &$row)); } $model->hydrate($row); $collection->add($model); } return $collection; }
/** * Prepare a statement * @param string $statement the SQL query * @param array $driver_options * @return \PdoStatement */ public function prepare($statement, $driver_options = []) { if (!is_null($this->pagination)) { $pagination_query = $this->paginateQuery($statement, $this->pagination->getCurrentPageNumber(), $this->pagination->getMaxResultsPerPage()); $count_query = $this->convertToCountQuery($statement); $primary_statement = parent::prepare($pagination_query, $driver_options); $count_statement = parent::prepare($count_query, $driver_options); $statement = new PdoStatement(); $statement->setPagination($this->pagination); $statement->setPrimaryStatement($primary_statement); $statement->setCountStatement($count_statement); // clear pagination $this->pagination = null; return $statement; } else { return parent::prepare($statement, $driver_options); } }
/** * @param PDOStatement $stmt * * @return array */ private function fetchData(PdoStatement $stmt) { $stmt->setFetchMode(PDO::FETCH_ASSOC); $resultAsArray = $stmt->fetchAll(); return $resultAsArray; }