You are here

function DB_common::getOne in Flickr API 5

Fetches the first column of the first row 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.

Return value

mixed the returned value of the query. A DB_Error object on failure.

2 calls to DB_common::getOne()
DB_mysql::nextId in phpFlickr/PEAR/DB/mysql.php
Returns the next free id in a sequence
DB_mysql::_BCsequence in phpFlickr/PEAR/DB/mysql.php
Backwards compatibility with old sequence emulation implementation (clean up the dupes)

File

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

Class

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

Code

function &getOne($query, $params = []) {
  $params = (array) $params;

  // 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, DB_FETCHMODE_ORDERED);
  $res
    ->free();
  if ($err !== DB_OK) {
    return $err;
  }
  return $row[0];
}