In programming languages there are 2 patterns for selecting records from the database:
//prepare SELECT statement
while($record = $query->fetchRow())
{
//do the job
}
And the second:
//prepare SELECT statement
$recordsArray = $query->fetchAllRows();
//do the job with all the records in a 2-dimensional array
To my surprise only the second option is available in JDatabaseQuery: loadRowList
, loadAssocList
etc.
When I tried:
$query = $db->getQuery(true);
$query->select(array('id', 'name'))
->from($db->quoteName('#__my_table'));
$db->setQuery($query);
while($row = $db->loadAssoc())
{
var_dump($row);
}
It hanged. Can I fetch the records one by one rather then get a 2-dimensional array?