To retrieve one row from the result set, use the fetch() method of the
statement object. Reference
$sql = SELECT blah blah FROM table ;
$stmt = $db->query($sql);
while ($row = $stmt->fetch()) {
// Process $row
}
在上述例子中,stmt =$db->query($sql);
检索resultset
, 并使用fetch
在座右铭上的现有行号resultset
,该行将 cur子移至下行,直至其到达上的最后一行。
To retrieve all the rows of the result set in one step, use the
fetchAll() method. This is equivalent to calling the fetch() method in
a loop and returning all the rows in an array.
$sql = SELECT blah blah FROM table ;
$stmt = $db->query($sql);
$rows = $stmt->fetchAll();
echo $rows[0][ col1 ]; // The first field/column from the first row
或者,你可以使用
....
$table = new Mytable();
// Find a single row Returns a Rowset
$rows = $table->find(1234);
// Find multiple rows Also returns a Rowset
$rows = $table->find(array(1234, 5678));
http://framework.zend.com/manual/en/zend.db.table.html。
www.un.org/spanish/ecosoc 更多:。
我想fetchAll()
是更快的,因为它以一个步骤检索所有数据,并回收一个阵列,但消耗更多的记忆,但fetch(<>fetch(>
)消耗的记忆较少,但取而代之的是数据。
The API for fetch operations has been superseded to allow a
Zend_Db_Table_Select object to modify the query. However, the
deprecated usage of the fetchRow() and fetchAll() methods will
continue to work without modification.
http://framework.zend.com/manual/en/zend.db.table.html