OK, so this one’s a little tricky.
I wrote a database abstraction layer for a CMS that I’m developing, and I’m trying to adapt it to use a flatfile DB. I am currently able to get all of my DB information into an array similar to that returned by mysql_fetch_assoc(). Here’s the problem though: it must remain compatible and provide the same functionality. Let me do an example.
To iterate throw the rows of a result, someone calls something like this:
[code=php]
while ($row = $db->dbRow($result)) {
echo $row[‘column’];
}
For the MySQL driver, the function looks like this:
[code=php]
function dbRow(&$result) {
return mysql_fetch_assoc($result);
}
This works perfectly. My problem, however, is what to do when I have an array? This creates an infinite loop:
[code=php]
function dbRow(&$result) {
$item = each($result);
if ($item == false) {
return false;
} else {
return $item[‘value’];
}
}
(I’ve tried many other things, but all seem to create some sort of infinite loop).
Suggestions?
-Matt