Hello,

Maybe I'm being a little stupid, but it has been a long year already!

We're trying to migrate from mysql to oracle and it is going fairly smoothly except for one important function: mysql_fetch_array

PHP has no real exact oracle equivalent so I wrote this to deliver precisely the same result:

function fetchArray ($stmt)
{

$i = 1;
while(OCIFetchinto($stmt,$row,OCI_ASSOC))
{

$j = 0;
while(list($col, $val) = each($row))
{

$array[$i][$j] = $val;
$array[$i][$col] = $val;
$j++;
}
$i++;
}

return $array;
}

The problem is how to functionise this so that when calling this function by doing something like:

while ($row = fetchArray($resource_id)){
echo "<br>\n do stuff to each row";
}

...it acts in exactly the same way as mysql did. I think the problem is the absence of some pointer or index that tells the oracle function what row to grab next.

Do you understand this problem, if so do you know how to solve it please?

Many thanks,

Jason

p.s. I'm already using metabase - but this function doesn't seem to exist in there for oracle.

    I didn't really look at your code but you said that there is no equivalent to mysql_fetch_array. Why not use the OCIFetchStatement function? This statement is functionally equivalent to mysql_fetch_array, but the syntax to use it is different.

    Here is an example from the manual:
    http://www.php.net/manual/en/function.ocifetchstatement.php

      I am already using this function but the problem is that to migrate the php scripts would mean replacing the existing mysq_fetch_array function with a few oracle functions including fetchinto.

      So what I wanted to do to make life easier was to replace mysql_fetch_array with 1 oracle function.

      If you try doing this and there's more than 1 row being fetched, how do you record the current row we're on, come out of the oracle function, do another iteration of the loop in the calling script, and then fetch the next row from within the oracle function?

      Capiche?

      Many thanks for helping...

      Jason

        There is nothing in PHP that will specifically tell you what the cursor location is in Oracle, if that's what you're asking. You can use a global variable (say $current_row) that can be used as a check in your fetchArray function. all you would need to do is set $current_row to 0 first, before calling fetchArray in the while loop of your script.

        The problem is that if there are tons of rows returned from the query, i believe you'll take a performance hit because you'll be continuously querying oracle and discarding the previous results you already used.

        Sorry if this doesn't help you much but i don't see any other way to do it, other than changing your code to use OCIFetchStatement, which i suggested earlier but you didn't want to do.

        BT

          Write a Reply...