0

I am using following code for fetch records. My code is working fine but it returns a array not a object. Any guess why this happening..

$select = $this->_db->select()
$select->from('users',array('id'));
if($where != '')
{
    $select->where($where);
}
$data = $this->_db->fetchRow($select);

Current output: echo $data['id'];

desire output: echo $data->id;

vijay2991
  • 131
  • 2
  • 4
  • 13

1 Answers1

0

You have to change the fetch mode, and use the query() method of your $select object :

$this->_db->setFetchMode(Zend_Db::FETCH_OBJ);
$select = $this->_db->select();
$select->from('users',array('id'));

if ($where != '') {
    $select->where($where);
}

$stmt = $select->query();
$data = $stmt->fetch();