Zend_Db_Table_Abstract::fetchRow PHP Method

fetchRow() public method

Fetches one row in an object of type Zend_Db_Table_Row_Abstract, or returns null if no row matches the specified criteria.
public fetchRow ( string | array | Zend_Db_Table_Select $where = null, string | array $order = null, integer $offset = null ) : Zend_Db_Table_Row_Abstract | null
$where string | array | Zend_Db_Table_Select OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
$order string | array OPTIONAL An SQL ORDER clause.
$offset integer OPTIONAL An SQL OFFSET value.
return Zend_Db_Table_Row_Abstract | null The row results per the Zend_Db_Adapter fetch mode, or null if no row found.
    public function fetchRow($where = null, $order = null, $offset = null)
    {
        if (!$where instanceof Zend_Db_Table_Select) {
            $select = $this->select();
            if ($where !== null) {
                $this->_where($select, $where);
            }
            if ($order !== null) {
                $this->_order($select, $order);
            }
            $select->limit(1, is_numeric($offset) ? (int) $offset : null);
        } else {
            $select = $where->limit(1, $where->getPart(Zend_Db_Select::LIMIT_OFFSET));
        }
        $rows = $this->_fetch($select);
        if (count($rows) == 0) {
            return null;
        }
        $data = array('table' => $this, 'data' => $rows[0], 'readOnly' => $select->isReadOnly(), 'stored' => true);
        $rowClass = $this->getRowClass();
        if (!class_exists($rowClass)) {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($rowClass);
        }
        return new $rowClass($data);
    }

Usage Example

Example #1
0
 public function getAttribute($id)
 {
     if (isset($this->_attributes[$id])) {
         return $this->_attributes[$id];
     } elseif (is_numeric($id)) {
         $attribute = $this->_attributeModel->find($id)->current();
     } else {
         $where = $this->_attributeModel->select()->where($this->_attributeFieldName . ' = ?', $id);
         $attribute = $this->_attributeModel->fetchRow($where);
     }
     $this->cacheAttribute($attribute);
     return $attribute;
 }
All Usage Examples Of Zend_Db_Table_Abstract::fetchRow