I want to fetch only one row from a database because I only expect one. However, with fetchAll
I always have to unwrap the array first before I can access the meat:
$result = self::$db->fetchAll($select);
$result = $result[0];
Is there a better solution?
You can also use the fetchRow
method, i.e.:
$result = self::$db->fetchRow($select);
// note that $result is a single object, not an array of objects
now you can access column name like this
$myResult = $result->columnName;
See http://framework.zend.com/manual/1.11/en/zend.db.adapter.html#zend.db.adapter.select.fetchrow
You can use the fetch
method. Try this:
$result = self::$db->query($select)->fetch();
Reference: http://framework.zend.com/manual/en/zend.db.statement.html#zend.db.statement.fetching.fetch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With