You are here

function DB_result::fetchInto in Flickr API 5

Fetch a row of data into an array which is passed by reference

The type of array returned can be controlled either by setting this method's <var>$fetchmode</var> parameter or by changing the default fetch mode setFetchMode() before calling this method.

There are two options for standardizing the information returned from databases, ensuring their values are consistent when changing DBMS's. These portability options can be turned on when creating a new DB object or by using setOption().

+ <var>DB_PORTABILITY_LOWERCASE</var> convert names of fields to lower case

+ <var>DB_PORTABILITY_RTRIM</var> right trim the data

Parameters

array &$arr the variable where the data should be placed:

int $fetchmode the constant indicating how to format the data:

int $rownum the row number to fetch (index starts at 0):

Return value

mixed DB_OK if a row is processed, NULL when the end of the result set is reached or a DB_Error object on failure

See also

DB_common::setOption(), DB_common::setFetchMode()

File

phpFlickr/PEAR/DB.php, line 1164

Class

DB_result
This class implements a wrapper for a DB result set

Code

function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null) {
  if ($fetchmode === DB_FETCHMODE_DEFAULT) {
    $fetchmode = $this->fetchmode;
  }
  if ($fetchmode === DB_FETCHMODE_OBJECT) {
    $fetchmode = DB_FETCHMODE_ASSOC;
    $object_class = $this->fetchmode_object_class;
  }
  if ($this->limit_from !== null) {
    if ($this->row_counter === null) {
      $this->row_counter = $this->limit_from;

      // Skip rows
      if ($this->dbh->features['limit'] === false) {
        $i = 0;
        while ($i++ < $this->limit_from) {
          $this->dbh
            ->fetchInto($this->result, $arr, $fetchmode);
        }
      }
    }
    if ($this->row_counter >= $this->limit_from + $this->limit_count) {
      if ($this->autofree) {
        $this
          ->free();
      }
      return null;
    }
    if ($this->dbh->features['limit'] === 'emulate') {
      $rownum = $this->row_counter;
    }
    $this->row_counter++;
  }
  $res = $this->dbh
    ->fetchInto($this->result, $arr, $fetchmode, $rownum);
  if ($res === DB_OK) {
    if (isset($object_class)) {

      // default mode specified in the
      // DB_common::fetchmode_object_class property
      if ($object_class == 'stdClass') {
        $arr = (object) $arr;
      }
      else {
        $arr = new $object_class($arr);
      }
    }
    return DB_OK;
  }
  if ($res == null && $this->autofree) {
    $this
      ->free();
  }
  return $res;
}