我希望从数据库中仅获取一行数据,因为我只需要一个。但是,使用
有更好的解决方案吗?
fetchAll
时,我总是需要先解开数组才能访问实际数据:$result = self::$db->fetchAll($select);
$result = $result[0];
有更好的解决方案吗?
fetchAll
时,我总是需要先解开数组才能访问实际数据:$result = self::$db->fetchAll($select);
$result = $result[0];
你也可以使用fetchRow
方法,例如:
$result = self::$db->fetchRow($select);
// note that $result is a single object, not an array of objects
现在你可以像这样访问列名
$myResult = $result->columnName;
请查看http://framework.zend.com/manual/1.11/en/zend.db.adapter.html#zend.db.adapter.select.fetchrow
fetch
方法。尝试这样做:$result = self::$db->query($select)->fetch();
参考:http://framework.zend.com/manual/en/zend.db.statement.html#zend.db.statement.fetching.fetch
这是一个关于it技术的参考链接。Call to undefined method Zend_Db_Adapter_Pdo_Mysql::fetch()
- Lenar Hoytfetch
,而不是数据库适配器。 - Chris Laplante