conn = $conn; $this->reset($sql, $bindings, $incarnation); } function reset(?string $sql, ?array &$bindings=null, ?IRowIncarnation $incarnation=null): self { if ($bindings === null) $bindings = []; $this->sql = $sql; $this->data =& $bindings; $this->incarnation = $incarnation; return $this; } function initStmt(?PDOStatement $stmt=null, ?callable $createStmtFunc=null): self { $this->stmt = $stmt; $this->createStmtFunc = $createStmtFunc; return $this; } /** créer une instance de PDOStatement */ protected function createStmt(): PDOStatement { $createStmtFunc = $this->createStmtFunc; if ($createStmtFunc !== null) { return func::call($createStmtFunc, $this->conn); } else { ["stmt" => $stmt ] = $this->conn->_execute($this->sql, $this->data, ["stmt" => true]); return $stmt; } } protected function _setup(): void { if ($this->stmt === null) { $incarnation = $this->incarnation; if ($incarnation !== null) { $incarnation->prepareBindings($this->data); } $this->stmt = $this->createStmt(); } } protected function _next() { return $this->stmt->fetch(PDO::FETCH_ASSOC); } protected function _cook(&$row, &$key): void { if ($this->incarnation !== null) { $this->incarnation->loadRow($row, $key); } } protected function _teardown(): void { if ($this->stmt !== null) { $this->stmt->closeCursor(); $this->stmt = null; } } function key() { return $this->_key(); } function current() { return $this->_current(); } }