1
0
mirror of synced 2025-02-06 15:29:26 +03:00

* added new fetchOne() method for convenience

* some whitespace cleanups
This commit is contained in:
mahono 2007-07-27 15:58:37 +00:00
parent 97e82445d7
commit c662f4d99f

View File

@ -904,9 +904,46 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
return $str;
}
/**
* fetchArray
* Convenience method to execute using array fetching as hydration mode.
*
* @param string $params
* @return array
*/
public function fetchArray($params = array()) {
return $this->execute($params, self::HYDRATE_ARRAY);
}
/**
* fetchOne
* Convenience method to execute the query and return the first item
* of the collection.
*
* @param string $params Parameters
* @param int $hydrationMode Hydration mode
* @return mixed Array or Doctrine_Collection or false if no result.
*/
public function fetchOne($params = array(), $hydrationMode = null)
{
if (is_null($hydrationMode)) {
$hydrationMode = $this->_hydrationMode;
}
$collection = $this->execute($params, $hydrationMode);
switch ($hydrationMode) {
case self::HYDRATE_RECORD:
if (count($collection) > 0) {
return $collection->getFirst();
}
case self::HYDRATE_ARRAY:
if (!empty($collection[0])) {
return $collection[0];
}
}
return false;
}
/**
* parseData
* parses the data returned by statement object