You are here

function DB_common::getRow in Flickr API 5

Fetches the first row of data returned from a query result

Takes care of doing the query and freeing the results when finished.

Parameters

string $query the SQL query:

mixed $params array, string or numeric data to be used in: execution of the statement. Quantity of items passed must match quantity of placeholders in query: meaning 1 placeholder for non-array parameters or 1 placeholder per array element.

int $fetchmode the fetch mode to use:

Return value

array the first row of results as an array. A DB_Error object on failure.

File

phpFlickr/PEAR/DB/common.php, line 1270

Class

DB_common
DB_common is the base class from which each database driver class extends

Code

function &getRow($query, $params = [], $fetchmode = DB_FETCHMODE_DEFAULT) {

  // compat check, the params and fetchmode parameters used to
  // have the opposite order
  if (!is_array($params)) {
    if (is_array($fetchmode)) {
      if ($params === null) {
        $tmp = DB_FETCHMODE_DEFAULT;
      }
      else {
        $tmp = $params;
      }
      $params = $fetchmode;
      $fetchmode = $tmp;
    }
    elseif ($params !== null) {
      $fetchmode = $params;
      $params = array();
    }
  }

  // modifyLimitQuery() would be nice here, but it causes BC issues
  if (sizeof($params) > 0) {
    $sth = $this
      ->prepare($query);
    if (DB::isError($sth)) {
      return $sth;
    }
    $res =& $this
      ->execute($sth, $params);
    $this
      ->freePrepared($sth);
  }
  else {
    $res =& $this
      ->query($query);
  }
  if (DB::isError($res)) {
    return $res;
  }
  $err = $res
    ->fetchInto($row, $fetchmode);
  $res
    ->free();
  if ($err !== DB_OK) {
    return $err;
  }
  return $row;
}