Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Adding support for different fetch mode #5

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions lib/Pheasant/Database/Mysqli/ResultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ResultIterator implements \SeekableIterator, \Countable
private $_position;
private $_currentRow;
private $_hydrator;
private $_fetchMode = MYSQLI_ASSOC;

/**
* Constructor
Expand Down Expand Up @@ -35,6 +36,25 @@ public function setHydrator($callback)
$this->_hydrator = $callback;
}

/**
* Set mysqli resultset fetchmode
* @param int [MYSQLI_ASSOC | MYSQLI_NUM | MYSQLI_BOTH]
*/
public function setFetchMode($mode)
{
$this->_fetchMode = $mode;
return $this;
}

/**
* Return mysqli resultset fetchmode
* @return int [MYSQLI_ASSOC | MYSQLI_NUM | MYSQLI_BOTH]
*/
public function getFetchMode()
{
return $this->_fetchMode;
}

/**
* Rewinds the internal pointer
*/
Expand Down Expand Up @@ -105,9 +125,9 @@ public function count()
*/
private function _fetch()
{
return isset($this->_hydrator)
? call_user_func($this->_hydrator, $this->_result->fetch_array(MYSQLI_ASSOC))
: $this->_result->fetch_array(MYSQLI_ASSOC)
return isset($this->_hydrator)
? call_user_func($this->_hydrator, $this->_result->fetch_array($this->_fetchMode))
: $this->_result->fetch_array($this->_fetchMode)
;
}
}
Expand Down