I've been working on a database wrapper class for a while now, MySQL to be specific. Until now, I've simply had a fetch function that returned an array of all the rows that the database returned, only because I have gotten so tired of always writing the same while loop to iterate through all the rows.
However, I have discovered that the method I'm using, passing around large multidimensional arrays of text by copy, is extremely memory inefficient, so I am working on a new method. Tell me if this is any better:
Rather than using something like:
$sql = 'SELECT text, date, etc FROM news WHERE blah=\'foo\'';
if (!$myquery = $db->query($sql)) { echo 'uh oh'; } if (!$db->numrows($myquery)) { echo 'no rows found'; }
$news = $db->fetchNews($myquery);
I could do something like:
$news = array(); $db->fetch($myquery, $news);
Where fetch($query, &$array) is the header. In the second case, the fetch function would therefore write the rows directly to the array which was passed as a reference rather than returning a copy. Am I right in thinking that this is a better method? Should I shut up and do a while loop?
Thanks,
Joachim
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php